Class: VagrantPlugins::Unison::Command
- Inherits:
-
Object
- Object
- VagrantPlugins::Unison::Command
- Includes:
- UnisonSync
- Defined in:
- lib/vagrant-unison-morroni/command.rb
Instance Method Summary collapse
Methods included from UnisonSync
Instance Method Details
#execute ⇒ Object
16 17 18 19 20 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 |
# File 'lib/vagrant-unison-morroni/command.rb', line 16 def execute with_target_vms do |machine| paths = UnisonPaths.new(@env, machine) host_path = paths.host sync(machine, paths) @env.ui.info "Watching #{host_path} for changes..." listener = Listen.to(host_path) 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? sync(machine, paths) end queue = Queue.new callback = lambda do # This needs to execute in another thread because Thread # synchronization can't happen in a trap context. Thread.new { queue << true } end # Run the listener in a busy block so that we can cleanly # exit once we receive an interrupt. Vagrant::Util::Busy.busy(callback) do listener.start queue.pop listener.stop if listener.listen? end end 0 end |
#sync(machine, paths) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/vagrant-unison-morroni/command.rb', line 53 def sync(machine, paths) execute_sync_command(machine) do |command| command.batch = true @env.ui.info "Running #{command.to_s}" r = Vagrant::Util::Subprocess.execute(*command.to_a) case r.exit_code when 0 @env.ui.info "Unison completed succesfully" when 1 @env.ui.info "Unison completed - all file transfers were successful; some files were skipped" when 2 @env.ui.info "Unison completed - non-fatal failures during file transfer: #{r.stderr}" else raise Vagrant::Errors::UnisonError, :command => command.to_s, :guestpath => paths.guest, :hostpath => paths.host, :stderr => r.stderr end end end |