class Synco::Methods::RSync

RSync Exit Codes as of 2011: 0 Success 1 Syntax or usage error 2 Protocol incompatibility 3 Errors selecting input/output files, dirs 4 Requested action not supported: an attempt was made to manipulate 64-bit files on a platform

that cannot support them; or an option was specified that is supported by the client and not by the server.

5 Error starting client-server protocol 6 Daemon unable to append to log-file 10 Error in socket I/O 11 Error in file I/O 12 Error in rsync protocol data stream 13 Errors with program diagnostics 14 Error in IPC code 20 Received SIGUSR1 or SIGINT 21 Some error returned by waitpid() 22 Error allocating core memory buffers 23 Partial transfer due to error 24 Partial transfer due to vanished source files 25 The –max-delete limit stopped deletions 30 Timeout in data send/receive 35 Timeout waiting for daemon connection

Public Class Methods

new(*command, arguments: [], archive: false, stats: nil, **options) click to toggle source
Calls superclass method Synco::Method::new
# File lib/synco/methods/rsync.rb, line 54
def initialize(*command, arguments: [], archive: false, stats: nil, **options)
        if archive
                arguments << '--archive'
        end
        
        if stats
                arguments << '--stats'
        end
        
        super
end

Public Instance Methods

call(scope) click to toggle source
# File lib/synco/methods/rsync.rb, line 94
def call(scope)
        master_server = scope.master_server
        target_server = scope.target_server
        directory = scope.directory
        
        master_server.run(
                *@command,
                *@arguments,
                *directory.arguments,
                *connect_arguments(master_server, target_server),
                master_server.connection_string(directory, on: master_server),
                target_server.connection_string(directory, on: master_server)
        )
rescue CommandFailure => failure
        raise unless failure.status.to_i == 24
end
connect_arguments(master_server, target_server) click to toggle source
# File lib/synco/methods/rsync.rb, line 78
def connect_arguments(master_server, target_server)
        return [] if master_server.same_host?(target_server)
        
        # This gives the command required to connect to the remote server, e.g. `ssh example.com`
        command = target_server.connection_command

        # RSync -e option simply appends the hostname. There is no way to control this behaviour.
        if command.last != target_server.host
                raise ArgumentError.new("RSync shell requires hostname at end of command! #{command.inspect}")
        else
                command.pop
        end

        return ['-e', escape(command)]
end
default_command() click to toggle source
# File lib/synco/methods/rsync.rb, line 50
def default_command
        ['rsync']
end
escape(command) click to toggle source

This escapes the -e argument to rsync, as it's argv parser is a bit.. unique.

# File lib/synco/methods/rsync.rb, line 67
def escape(command)
        case command
        when Array
                command.collect{|arg| escape(arg)}.join(' ')
        when String
                command =~ /\s|"|'/ ? command.dump : command
        else
                escape(command.to_s)
        end
end