vagrant-unison 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,6 @@
1
1
  require "log4r"
2
2
  require "vagrant"
3
3
  require 'listen'
4
- require 'net/ssh'
5
- require 'net/scp'
6
4
 
7
5
  module VagrantPlugins
8
6
  module Unison
@@ -12,52 +10,18 @@ module VagrantPlugins
12
10
 
13
11
  with_target_vms do |machine|
14
12
  hostpath, guestpath = init_paths machine
15
-
16
- ssh_info = machine.ssh_info
17
-
18
- # Create empty guestpath
19
- machine.communicate.sudo("rm -rf '#{guestpath}'")
20
- machine.communicate.sudo("mkdir -p '#{guestpath}'")
21
- machine.communicate.sudo("chown #{ssh_info[:username]} '#{guestpath}'")
22
13
 
23
- Net::SCP.start(ssh_info[:host], ssh_info[:username],
24
- { :port => ssh_info[:port],
25
- :keys => [ ssh_info[:private_key_path] ],
26
- :paranoid => false }) do |scp|
14
+ trigger_unison_sync machine
27
15
 
28
- #copy up everything at the beginning
29
- @env.ui.info "Uploading {host}::#{hostpath} to {guest}::#{guestpath}"
30
- Dir.glob("#{hostpath}**/*", File::FNM_DOTMATCH).each do |file|
31
- remote_file = file.gsub(hostpath, guestpath)
32
- if File.stat(file).file?
33
- scp.upload!( file, remote_file ) do |ch, name, sent, total|
34
- @env.ui.info "\r#{name}: #{(sent.to_f * 100 / total.to_f).to_i}%"
35
- end
36
- end
37
- if File.directory?(file)
38
- machine.communicate.sudo("mkdir -p '#{remote_file}'")
39
- machine.communicate.sudo("chown #{ssh_info[:username]} '#{remote_file}'")
40
- end
41
- end
42
-
43
- @env.ui.info "Watching {host}::#{hostpath} for changes..."
44
-
45
- Listen.to(hostpath) do |modified, added, removed|
46
- (modified << added).flatten.each do |file|
47
- remote_file = file.gsub(hostpath, guestpath)
48
- @env.ui.info "Uploading {host}::#{file} to {guest VM}::#{remote_file}"
49
- scp.upload!( file, remote_file ) do |ch, name, sent, total|
50
- @env.ui.info "\r#{name}: #{(sent.to_f * 100 / total.to_f).to_i}%"
51
- end
52
- end
53
- removed.each do |file|
54
- remote_file = file.gsub(hostpath, guestpath)
55
- @env.ui.info "Deleting {guest VM}::#{remote_file}"
56
- machine.communicate.sudo("rm #{remote_file}")
57
- end
58
- end # Listen
59
- end # Net::SCP.start
16
+ @env.ui.info "Watching #{hostpath} for changes..."
60
17
 
18
+ Listen.to(hostpath) do |modified, added, removed|
19
+ @env.ui.info "Detected modifications to #{modified.inspect}" unless modified.empty?
20
+ @env.ui.info "Detected new files #{added.inspect}" unless added.empty?
21
+ @env.ui.info "Detected deleted files #{removed.inspect}" unless removed.empty?
22
+
23
+ trigger_unison_sync machine
24
+ end
61
25
  end
62
26
 
63
27
  0 #all is well
@@ -67,12 +31,42 @@ module VagrantPlugins
67
31
  hostpath = File.expand_path(machine.config.sync.host_folder, @env.root_path)
68
32
  guestpath = machine.config.sync.guest_folder
69
33
 
70
- # Make sure there is a trailing slash both paths
34
+ # Make sure there is a trailing slash on the host path to
35
+ # avoid creating an additional directory with rsync
71
36
  hostpath = "#{hostpath}/" if hostpath !~ /\/$/
72
- guestpath = "#{guestpath}/" if guestpath !~ /\/$/
73
37
 
74
38
  [hostpath, guestpath]
75
39
  end
40
+
41
+ def trigger_unison_sync(machine)
42
+ hostpath, guestpath = init_paths machine
43
+
44
+ @env.ui.info "Unisoning changes from {host}::#{hostpath} --> {guest VM}::#{guestpath}"
45
+
46
+ ssh_info = machine.ssh_info
47
+
48
+ # Create the guest path
49
+ machine.communicate.sudo("mkdir -p '#{guestpath}'")
50
+ machine.communicate.sudo("chown #{ssh_info[:username]} '#{guestpath}'")
51
+
52
+ # Unison over to the guest path using the SSH info
53
+ command = [
54
+ "unison", "-batch",
55
+ "-ignore=Name {.git*,.vagrant/,*.DS_Store}",
56
+ "-sshargs", "-p #{ssh_info[:port]} -o StrictHostKeyChecking=no -i #{ssh_info[:private_key_path]}",
57
+ hostpath,
58
+ "ssh://#{ssh_info[:username]}@#{ssh_info[:host]}/#{guestpath}"
59
+ ]
60
+
61
+ r = Vagrant::Util::Subprocess.execute(*command)
62
+ if r.exit_code != 0
63
+ raise Vagrant::Errors::UnisonError,
64
+ :command => command.inspect,
65
+ :guestpath => guestpath,
66
+ :hostpath => hostpath,
67
+ :stderr => r.stderr
68
+ end
69
+ end
76
70
 
77
71
  end
78
72
  end
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module Unison
3
- VERSION = "0.0.8"
3
+ VERSION = "0.0.9"
4
4
  end
5
5
  end
@@ -15,7 +15,6 @@ Gem::Specification.new do |s|
15
15
 
16
16
  s.add_runtime_dependency "listen", "~> 0.7.3"
17
17
  s.add_runtime_dependency "rb-fsevent", "~> 0.9"
18
- s.add_runtime_dependency "net-scp", "~> 1.1.0"
19
18
 
20
19
  s.add_development_dependency "rake"
21
20
  s.add_development_dependency "rspec-core", "~> 2.12.2"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-unison
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -43,22 +43,6 @@ dependencies:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0.9'
46
- - !ruby/object:Gem::Dependency
47
- name: net-scp
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ~>
52
- - !ruby/object:Gem::Version
53
- version: 1.1.0
54
- type: :runtime
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ~>
60
- - !ruby/object:Gem::Version
61
- version: 1.1.0
62
46
  - !ruby/object:Gem::Dependency
63
47
  name: rake
64
48
  requirement: !ruby/object:Gem::Requirement
@@ -158,7 +142,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
158
142
  version: '0'
159
143
  segments:
160
144
  - 0
161
- hash: 3608198865268606227
145
+ hash: -2151286611180644825
162
146
  required_rubygems_version: !ruby/object:Gem::Requirement
163
147
  none: false
164
148
  requirements: