Class: Vagrant::Syncer::Command::RsyncAuto

Inherits:
Object
  • Object
show all
Includes:
Action::Builtin::MixinSyncedFolders
Defined in:
lib/syncer/command/rsync_auto.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.synopsisObject



17
18
19
# File 'lib/syncer/command/rsync_auto.rb', line 17

def self.synopsis
  "syncs rsync synced folders automatically when files change"
end

Instance Method Details

#executeObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/syncer/command/rsync_auto.rb', line 21

def execute
  @logger = Log4r::Logger.new("vagrant::commands::rsync-auto")

  options = {}
  opts = OptionParser.new do |o|
    o.banner = "Usage: vagrant rsync-auto [vm-name]"
    o.separator ""
    o.separator "Options:"
    o.separator ""

    o.on("--[no-]poll", "Force polling filesystem (slow)") do |poll|
      options[:poll] = poll
    end
  end

  # Parse the options and return if we don't have any target.
  argv = parse_options(opts)
  return  unless argv

  machine_threads = []

  # Build up the paths that we need to listen to.
  with_target_vms(argv) do |machine|
    if machine.provider.capability?(:proxy_machine)
      proxy = machine.provider.capability(:proxy_machine)
      if proxy
        machine.ui.warn(I18n.t(
          "vagrant.rsync_proxy_machine",
          name: machine.name.to_s,
          provider: machine.provider_name.to_s
        ))
        machine = proxy
      end
    end

    next  unless machine.communicate.ready?
    next  unless synced_folders(machine)[:rsync]

    if machine.ssh_info
      target_machine = Machine.new(machine)
      machine_threads << Thread.new do
        target_machine.full_sync
        target_machine.listen(options[:poll])
      end
    end
  end
  machine_threads.each { |t| t.join }

  return 0
end