Class: Caterer::Communication::Rsync

Inherits:
Object
  • Object
show all
Defined in:
lib/caterer/communication/rsync.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server) ⇒ Rsync

Returns a new instance of Rsync.



18
19
20
21
# File 'lib/caterer/communication/rsync.rb', line 18

def initialize(server)
  @server = server
  @logger = Log4r::Logger.new("caterer::communication::rsync")
end

Instance Attribute Details

#serverObject (readonly)

Returns the value of attribute server.



7
8
9
# File 'lib/caterer/communication/rsync.rb', line 7

def server
  @server
end

Class Method Details

.available?Boolean

Returns:

  • (Boolean)


11
12
13
14
# File 'lib/caterer/communication/rsync.rb', line 11

def available?
  `command -v rsync &>/dev/null`
  $?.exitstatus == 0 ? true : false
end

Instance Method Details

#sync(from, to) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/caterer/communication/rsync.rb', line 23

def sync(from, to)
  exit_status = nil
  PTY.spawn(rsync_cmd(from, to)) do |stdout, stdin, pid|
    eof = false
    until eof do
      begin
        out = stdout.readpartial(4096)
        if out.match /(p|P)assword:/
          stdin.puts server.password
        else
          @logger.debug("stdout: #{out}")
        end
      rescue EOFError, Errno::EIO
        eof = true
      end
    end
    Process.wait(pid)
    exit_status = $?.exitstatus
  end
  exit_status
end