vagrant-unison 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/vagrant-unison/command.rb +31 -51
- data/lib/vagrant-unison/version.rb +1 -1
- metadata +2 -2
@@ -15,38 +15,48 @@ module VagrantPlugins
|
|
15
15
|
|
16
16
|
ssh_info = machine.ssh_info
|
17
17
|
|
18
|
-
# Create
|
18
|
+
# Create empty guestpath
|
19
|
+
machine.communicate.sudo("rm -rf '#{guestpath}'")
|
19
20
|
machine.communicate.sudo("mkdir -p '#{guestpath}'")
|
20
21
|
machine.communicate.sudo("chown #{ssh_info[:username]} '#{guestpath}'")
|
21
22
|
|
22
|
-
#copy up everything at the beginning
|
23
23
|
Net::SCP.start(ssh_info[:host], ssh_info[:username],
|
24
24
|
{ :port => ssh_info[:port],
|
25
|
-
:keys => [ ssh_info[:private_key_path],
|
26
|
-
:paranoid => false
|
27
|
-
|
28
|
-
|
25
|
+
:keys => [ ssh_info[:private_key_path] ],
|
26
|
+
:paranoid => false }) do |scp|
|
27
|
+
|
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
|
29
42
|
|
30
|
-
|
43
|
+
@env.ui.info "Watching {host}::#{hostpath} for changes..."
|
31
44
|
|
32
|
-
|
33
|
-
|
34
|
-
{ :port => ssh_info[:port],
|
35
|
-
:keys => [ ssh_info[:private_key_path],
|
36
|
-
:paranoid => false ] }) do |scp|
|
37
|
-
(modified_list << added_list).flatten.each do |file|
|
45
|
+
Listen.to(hostpath) do |modified, added, removed|
|
46
|
+
(modified << added).flatten.each do |file|
|
38
47
|
remote_file = file.gsub(hostpath, guestpath)
|
39
|
-
@env.ui.info "Uploading
|
40
|
-
scp.upload! file, remote_file
|
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
|
41
52
|
end
|
42
53
|
removed.each do |file|
|
43
54
|
remote_file = file.gsub(hostpath, guestpath)
|
44
|
-
@env.ui.info "Deleting
|
55
|
+
@env.ui.info "Deleting {guest VM}::#{remote_file}"
|
45
56
|
machine.communicate.sudo("rm #{remote_file}")
|
46
57
|
end
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
58
|
+
end # Listen
|
59
|
+
end # Net::SCP.start
|
50
60
|
|
51
61
|
end
|
52
62
|
|
@@ -57,42 +67,12 @@ module VagrantPlugins
|
|
57
67
|
hostpath = File.expand_path(machine.config.sync.host_folder, @env.root_path)
|
58
68
|
guestpath = machine.config.sync.guest_folder
|
59
69
|
|
60
|
-
# Make sure there is a trailing slash
|
61
|
-
# avoid creating an additional directory with rsync
|
70
|
+
# Make sure there is a trailing slash both paths
|
62
71
|
hostpath = "#{hostpath}/" if hostpath !~ /\/$/
|
72
|
+
guestpath = "#{guestpath}/" if guestpath !~ /\/$/
|
63
73
|
|
64
74
|
[hostpath, guestpath]
|
65
75
|
end
|
66
|
-
|
67
|
-
def trigger_unison_sync(machine)
|
68
|
-
hostpath, guestpath = init_paths machine
|
69
|
-
|
70
|
-
@env.ui.info "Unisoning changes from {host}::#{hostpath} --> {guest VM}::#{guestpath}"
|
71
|
-
|
72
|
-
ssh_info = machine.ssh_info
|
73
|
-
|
74
|
-
# Create the guest path
|
75
|
-
machine.communicate.sudo("mkdir -p '#{guestpath}'")
|
76
|
-
machine.communicate.sudo("chown #{ssh_info[:username]} '#{guestpath}'")
|
77
|
-
|
78
|
-
# Unison over to the guest path using the SSH info
|
79
|
-
command = [
|
80
|
-
"unison", "-batch",
|
81
|
-
"-ignore=Name {.git*,.vagrant/,*.DS_Store}",
|
82
|
-
"-sshargs", "-p #{ssh_info[:port]} -o StrictHostKeyChecking=no -i #{ssh_info[:private_key_path]}",
|
83
|
-
hostpath,
|
84
|
-
"ssh://#{ssh_info[:username]}@#{ssh_info[:host]}/#{guestpath}"
|
85
|
-
]
|
86
|
-
|
87
|
-
r = Vagrant::Util::Subprocess.execute(*command)
|
88
|
-
if r.exit_code != 0
|
89
|
-
raise Vagrant::Errors::UnisonError,
|
90
|
-
:command => command.inspect,
|
91
|
-
:guestpath => guestpath,
|
92
|
-
:hostpath => hostpath,
|
93
|
-
:stderr => r.stderr
|
94
|
-
end
|
95
|
-
end
|
96
76
|
|
97
77
|
end
|
98
78
|
end
|
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.
|
4
|
+
version: 0.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -158,7 +158,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
158
158
|
version: '0'
|
159
159
|
segments:
|
160
160
|
- 0
|
161
|
-
hash:
|
161
|
+
hash: 3608198865268606227
|
162
162
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
163
163
|
none: false
|
164
164
|
requirements:
|