vagrant-rsync-only-changed 0.5.0 → 0.6.0
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.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5fde9ce9979c3f56fdf77ef38938294c0f534ad1
|
4
|
+
data.tar.gz: d5a3ff96c2537143cd5a19dc11892fc52421213f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ceb9c1f835dc746e2bb2542067d75a310cb91b8fb6e118ca79e242a82115dd2351bb10b4f8380b076ad4f3fbe09d983253edb8904671a17e782e235c8865d88b
|
7
|
+
data.tar.gz: 65a06b41aebbd0d091aec20ffc4395a60359318b45dae01e67f52b1eb8f24894e3cad8452142de90ed02335a2917ad4469da8df989ee77432216fc6d37ceebfd
|
@@ -22,187 +22,185 @@ require "listen"
|
|
22
22
|
|
23
23
|
module VagrantPlugins
|
24
24
|
module RsyncOnlyChanged
|
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
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
end
|
205
|
-
end
|
206
|
-
end
|
25
|
+
class RsyncOnlyChangedAuto < Vagrant.plugin("2", :command)
|
26
|
+
include Vagrant::Action::Builtin::MixinSyncedFolders
|
27
|
+
|
28
|
+
def self.synopsis
|
29
|
+
"syncs rsync synced folders automatically when files change"
|
30
|
+
end
|
31
|
+
|
32
|
+
def execute
|
33
|
+
@logger = Log4r::Logger.new("vagrant::commands::rsync-auto-only-changed")
|
34
|
+
|
35
|
+
options = {}
|
36
|
+
opts = OptionParser.new do |o|
|
37
|
+
o.banner = "Usage: vagrant rsync-auto-only-changed [vm-name]"
|
38
|
+
o.separator ""
|
39
|
+
o.separator "Options:"
|
40
|
+
o.separator ""
|
41
|
+
|
42
|
+
o.on("--[no-]poll", "Force polling filesystem (slow)") do |poll|
|
43
|
+
options[:poll] = poll
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Parse the options and return if we don't have any target.
|
48
|
+
argv = parse_options(opts)
|
49
|
+
return if !argv
|
50
|
+
|
51
|
+
# Build up the paths that we need to listen to.
|
52
|
+
paths = {}
|
53
|
+
ignores = []
|
54
|
+
with_target_vms(argv) do |machine|
|
55
|
+
if machine.provider.capability?(:proxy_machine)
|
56
|
+
proxy = machine.provider.capability(:proxy_machine)
|
57
|
+
if proxy
|
58
|
+
machine.ui.warn(I18n.t(
|
59
|
+
"vagrant.rsync_proxy_machine",
|
60
|
+
name: machine.name.to_s,
|
61
|
+
provider: machine.provider_name.to_s))
|
62
|
+
|
63
|
+
machine = proxy
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
cached = synced_folders(machine, cached: true)
|
68
|
+
fresh = synced_folders(machine)
|
69
|
+
diff = synced_folders_diff(cached, fresh)
|
70
|
+
if !diff[:added].empty?
|
71
|
+
machine.ui.warn(I18n.t("vagrant.rsync_auto_new_folders"))
|
72
|
+
end
|
73
|
+
|
74
|
+
folders = cached[:rsync]
|
75
|
+
next if !folders || folders.empty?
|
76
|
+
|
77
|
+
# Get the SSH info for this machine so we can do an initial
|
78
|
+
# sync to the VM.
|
79
|
+
ssh_info = machine.ssh_info
|
80
|
+
if ssh_info
|
81
|
+
machine.ui.info(I18n.t("vagrant.rsync_auto_initial"))
|
82
|
+
folders.each do |id, folder_opts|
|
83
|
+
RsyncHelper.rsync_single(machine, ssh_info, folder_opts)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
folders.each do |id, folder_opts|
|
88
|
+
# If we marked this folder to not auto sync, then
|
89
|
+
# don't do it.
|
90
|
+
next if folder_opts.key?(:auto) && !folder_opts[:auto]
|
91
|
+
|
92
|
+
hostpath = folder_opts[:hostpath]
|
93
|
+
hostpath = File.expand_path(hostpath, machine.env.root_path)
|
94
|
+
paths[hostpath] ||= []
|
95
|
+
paths[hostpath] << {
|
96
|
+
id: id,
|
97
|
+
machine: machine,
|
98
|
+
opts: folder_opts,
|
99
|
+
}
|
100
|
+
|
101
|
+
if folder_opts[:exclude]
|
102
|
+
Array(folder_opts[:exclude]).each do |pattern|
|
103
|
+
ignores << RsyncHelper.exclude_to_regexp(hostpath, pattern.to_s)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# Exit immediately if there is nothing to watch
|
110
|
+
if paths.empty?
|
111
|
+
@env.ui.info(I18n.t("vagrant.rsync_auto_no_paths"))
|
112
|
+
return 1
|
113
|
+
end
|
114
|
+
|
115
|
+
# Output to the user what paths we'll be watching
|
116
|
+
paths.keys.sort.each do |path|
|
117
|
+
paths[path].each do |path_opts|
|
118
|
+
path_opts[:machine].ui.info(I18n.t(
|
119
|
+
"vagrant.rsync_auto_path",
|
120
|
+
path: path.to_s,
|
121
|
+
))
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
@logger.info("Listening to paths: #{paths.keys.sort.inspect}")
|
126
|
+
@logger.info("Ignoring #{ignores.length} paths:")
|
127
|
+
ignores.each do |ignore|
|
128
|
+
@logger.info(" -- #{ignore.to_s}")
|
129
|
+
end
|
130
|
+
@logger.info("Listening via: #{Listen::Adapter.select.inspect}")
|
131
|
+
callback = method(:callback).to_proc.curry[paths]
|
132
|
+
listopts = { ignore: ignores, force_polling: !!options[:poll] }
|
133
|
+
listener = Listen.to(*paths.keys, listopts, &callback)
|
134
|
+
|
135
|
+
# Create the callback that lets us know when we've been interrupted
|
136
|
+
queue = Queue.new
|
137
|
+
callback = lambda do
|
138
|
+
# This needs to execute in another thread because Thread
|
139
|
+
# synchronization can't happen in a trap context.
|
140
|
+
Thread.new { queue << true }
|
141
|
+
end
|
142
|
+
|
143
|
+
# Run the listener in a busy block so that we can cleanly
|
144
|
+
# exit once we receive an interrupt.
|
145
|
+
Vagrant::Util::Busy.busy(callback) do
|
146
|
+
listener.start
|
147
|
+
queue.pop
|
148
|
+
listener.stop if listener.state != :stopped
|
149
|
+
end
|
150
|
+
|
151
|
+
0
|
152
|
+
end
|
153
|
+
|
154
|
+
# This is the callback that is called when any changes happen
|
155
|
+
def callback(paths, modified, added, removed)
|
156
|
+
@logger.info("File change callback called!")
|
157
|
+
@logger.info(" - Modified: #{modified.inspect}")
|
158
|
+
@logger.info(" - Added: #{added.inspect}")
|
159
|
+
@logger.info(" - Removed: #{removed.inspect}")
|
160
|
+
|
161
|
+
toSyncPaths = Hash.new
|
162
|
+
|
163
|
+
paths.each do |hostpath, folders|
|
164
|
+
changed_paths = []
|
165
|
+
[modified, added, removed].each do |changed|
|
166
|
+
changed.each do |listenpath|
|
167
|
+
if listenpath.start_with?(hostpath)
|
168
|
+
changed_paths << listenpath
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
if changed_paths.any?
|
174
|
+
toSyncPaths[folders] = changed_paths
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
# Sync all the folders that need to be synced
|
179
|
+
toSyncPaths.each do |folders, changed_paths|
|
180
|
+
folders.each do |opts|
|
181
|
+
# Reload so we get the latest ID
|
182
|
+
opts[:machine].reload
|
183
|
+
if !opts[:machine].id || opts[:machine].id == ""
|
184
|
+
# Skip since we can't get SSH info without an ID
|
185
|
+
next
|
186
|
+
end
|
187
|
+
|
188
|
+
ssh_info = opts[:machine].ssh_info
|
189
|
+
begin
|
190
|
+
VagrantPlugins::RsyncOnlyChanged::RsyncHelper.rsync_single(opts[:machine], ssh_info, opts[:opts], changed_paths)
|
191
|
+
rescue Vagrant::Errors::MachineGuestNotReady
|
192
|
+
# Error communicating to the machine, probably a reload or
|
193
|
+
# halt is happening. Just notify the user but don't fail out.
|
194
|
+
opts[:machine].ui.error(I18n.t(
|
195
|
+
"vagrant.rsync_communicator_not_ready_callback"))
|
196
|
+
rescue Vagrant::Errors::RSyncError => e
|
197
|
+
# Error executing rsync, so show an error
|
198
|
+
opts[:machine].ui.error(I18n.t(
|
199
|
+
"vagrant.rsync_auto_rsync_error", message: e.to_s))
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
207
204
|
end
|
208
205
|
end
|
206
|
+
end
|
@@ -13,6 +13,14 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.description = %q{Currently Vagrant rsync-auto command will always issue a full rsync when an event is detected during rsync-auto. With this plugin rsync will be called with the parameter --files-from with only the added/changed/removed files and/or directories listed. This will speed up a lot the command for big file trees.}
|
14
14
|
spec.homepage = "https://github.com/nuncanada/vagrant-rsync-only-changed"
|
15
15
|
|
16
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
17
|
+
# delete this section to allow pushing this gem to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
20
|
+
else
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
22
|
+
end
|
23
|
+
|
16
24
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
25
|
spec.bindir = "exe"
|
18
26
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-rsync-only-changed
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Flávio Botelho
|
@@ -66,7 +66,8 @@ files:
|
|
66
66
|
- vagrant-rsync-only-changed.gemspec
|
67
67
|
homepage: https://github.com/nuncanada/vagrant-rsync-only-changed
|
68
68
|
licenses: []
|
69
|
-
metadata:
|
69
|
+
metadata:
|
70
|
+
allowed_push_host: https://rubygems.org
|
70
71
|
post_install_message:
|
71
72
|
rdoc_options: []
|
72
73
|
require_paths:
|