Class: Downloads::Commands::Sync

Inherits:
Base
  • Object
show all
Defined in:
lib/downloads/commands/sync.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#configuration, #local, #options, #remote

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

command_name, inherited, #initialize, #usage, #valid?

Constructor Details

This class inherits a constructor from Downloads::Commands::Base

Instance Attribute Details

#killObject

Returns the value of attribute kill.



4
5
6
# File 'lib/downloads/commands/sync.rb', line 4

def kill
  @kill
end

Class Method Details

.usageObject



6
7
8
# File 'lib/downloads/commands/sync.rb', line 6

def self.usage
  "#{super} [kill]"
end

Instance Method Details

#configure(argv) ⇒ Object



10
11
12
# File 'lib/downloads/commands/sync.rb', line 10

def configure(argv)
  self.kill = (shift_argument(argv) == 'kill')
end

#runObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/downloads/commands/sync.rb', line 14

def run
  if File.exists?(pid_file)
    `kill #{File.read(pid_file)}`
    File.delete(pid_file)
  end

  unless kill
    pid = fork { exec("rsync --recursive --progress --partial #{remote.rsync_path} #{local.rsync_path}") }
    File.open(pid_file, 'w') { |file| file.write(pid) }

    begin
      Process.wait
    rescue Interrupt
      # we don't need to see the stacktrace
      puts # but a blank line is nice
    end
  end
end