Class: Synco::Methods::RSync

Inherits:
Synco::Method show all
Defined in:
lib/synco/methods/rsync.rb

Overview

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

Direct Known Subclasses

RSyncSnapshot

Instance Attribute Summary

Attributes inherited from Synco::Method

#arguments, #options

Attributes inherited from Controller

#events

Instance Method Summary collapse

Methods inherited from Controller

#abort!, build, #fire, #freeze, #on, #try

Constructor Details

#initialize(*command, arguments: [], archive: false, stats: nil, **options) ⇒ RSync

Returns a new instance of RSync.



54
55
56
57
58
59
60
61
62
63
64
# 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

Instance Method Details

#call(scope) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# 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) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# 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_commandObject



50
51
52
# File 'lib/synco/methods/rsync.rb', line 50

def default_command
  ['rsync']
end

#escape(command) ⇒ Object

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



67
68
69
70
71
72
73
74
75
76
# 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