Class: VagrantPlugins::Unison::Command
- Inherits:
-
Object
- Object
- VagrantPlugins::Unison::Command
- Defined in:
- lib/vagrant-unison/command.rb
Instance Method Summary collapse
Instance Method Details
#execute ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/vagrant-unison/command.rb', line 9 def execute with_target_vms do |machine| hostpath, guestpath = init_paths machine trigger_unison_sync machine @env.ui.info "Watching #{hostpath} for changes..." Listen.to(hostpath) do |modified, added, removed| @env.ui.info "Detected modifications to #{modified.inspect}" unless modified.empty? @env.ui.info "Detected new files #{added.inspect}" unless added.empty? @env.ui.info "Detected deleted files #{removed.inspect}" unless removed.empty? trigger_unison_sync machine end end 0 #all is well end |
#init_paths(machine) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/vagrant-unison/command.rb', line 30 def init_paths(machine) hostpath = File.(machine.config.sync.host_folder, @env.root_path) guestpath = machine.config.sync.guest_folder # Make sure there is a trailing slash on the host path to # avoid creating an additional directory with rsync hostpath = "#{hostpath}/" if hostpath !~ /\/$/ [hostpath, guestpath] end |
#trigger_unison_sync(machine) ⇒ Object
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 |
# File 'lib/vagrant-unison/command.rb', line 41 def trigger_unison_sync(machine) hostpath, guestpath = init_paths machine @env.ui.info "Unisoning changes from {host}::#{hostpath} --> {guest VM}::#{guestpath}" ssh_info = machine.ssh_info # Create the guest path machine.communicate.sudo("mkdir -p '#{guestpath}'") machine.communicate.sudo("chown #{ssh_info[:username]} '#{guestpath}'") # Unison over to the guest path using the SSH info command = [ "unison", "-batch", "-ignore=Name {.git*,.vagrant/,*.DS_Store}", "-sshargs", "-p #{ssh_info[:port]} -o StrictHostKeyChecking=no -i #{ssh_info[:private_key_path]}", hostpath, "ssh://#{ssh_info[:username]}@#{ssh_info[:host]}/#{guestpath}" ] r = Vagrant::Util::Subprocess.execute(*command) if r.exit_code != 0 raise Vagrant::Errors::UnisonError, :command => command.inspect, :guestpath => guestpath, :hostpath => hostpath, :stderr => r.stderr end end |