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: 19b21c8078ed412f7a9f550e5d34dcbbcbc79ddc
4
- data.tar.gz: 26ed3e283a53874f0a8b12ffb7e7cfe366279ed8
3
+ metadata.gz: 5fde9ce9979c3f56fdf77ef38938294c0f534ad1
4
+ data.tar.gz: d5a3ff96c2537143cd5a19dc11892fc52421213f
5
5
  SHA512:
6
- metadata.gz: e9c41278bc21bc1a7abe11cc2dcc65b02fa7b178a54280e08aa62829bf723db25e3e1017df56b9a42bad8dfed532c881db6ff0f9ff5dd651b402e4eb44a8db49
7
- data.tar.gz: 0a54d6abce4d152809f1fb1f6e8112c0f821241ca87c7656ae7f720f776ad77cca69e323225fe46f8d11d6706cb5a3f40886700f4cd577cd2c574ab86eff4be9
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
- module Command
26
- class RsyncOnlyChangedAuto < Vagrant.plugin("2", :command)
27
- include Vagrant::Action::Builtin::MixinSyncedFolders
28
-
29
- def self.synopsis
30
- "syncs rsync synced folders automatically when files change"
31
- end
32
-
33
- def execute
34
- @logger = Log4r::Logger.new("vagrant::commands::rsync-auto-only-changed")
35
-
36
- options = {}
37
- opts = OptionParser.new do |o|
38
- o.banner = "Usage: vagrant rsync-auto-only-changed [vm-name]"
39
- o.separator ""
40
- o.separator "Options:"
41
- o.separator ""
42
-
43
- o.on("--[no-]poll", "Force polling filesystem (slow)") do |poll|
44
- options[:poll] = poll
45
- end
46
- end
47
-
48
- # Parse the options and return if we don't have any target.
49
- argv = parse_options(opts)
50
- return if !argv
51
-
52
- # Build up the paths that we need to listen to.
53
- paths = {}
54
- ignores = []
55
- with_target_vms(argv) do |machine|
56
- if machine.provider.capability?(:proxy_machine)
57
- proxy = machine.provider.capability(:proxy_machine)
58
- if proxy
59
- machine.ui.warn(I18n.t(
60
- "vagrant.rsync_proxy_machine",
61
- name: machine.name.to_s,
62
- provider: machine.provider_name.to_s))
63
-
64
- machine = proxy
65
- end
66
- end
67
-
68
- cached = synced_folders(machine, cached: true)
69
- fresh = synced_folders(machine)
70
- diff = synced_folders_diff(cached, fresh)
71
- if !diff[:added].empty?
72
- machine.ui.warn(I18n.t("vagrant.rsync_auto_new_folders"))
73
- end
74
-
75
- folders = cached[:rsync]
76
- next if !folders || folders.empty?
77
-
78
- # Get the SSH info for this machine so we can do an initial
79
- # sync to the VM.
80
- ssh_info = machine.ssh_info
81
- if ssh_info
82
- machine.ui.info(I18n.t("vagrant.rsync_auto_initial"))
83
- folders.each do |id, folder_opts|
84
- RsyncHelper.rsync_single(machine, ssh_info, folder_opts)
85
- end
86
- end
87
-
88
- folders.each do |id, folder_opts|
89
- # If we marked this folder to not auto sync, then
90
- # don't do it.
91
- next if folder_opts.key?(:auto) && !folder_opts[:auto]
92
-
93
- hostpath = folder_opts[:hostpath]
94
- hostpath = File.expand_path(hostpath, machine.env.root_path)
95
- paths[hostpath] ||= []
96
- paths[hostpath] << {
97
- id: id,
98
- machine: machine,
99
- opts: folder_opts,
100
- }
101
-
102
- if folder_opts[:exclude]
103
- Array(folder_opts[:exclude]).each do |pattern|
104
- ignores << RsyncHelper.exclude_to_regexp(hostpath, pattern.to_s)
105
- end
106
- end
107
- end
108
- end
109
-
110
- # Exit immediately if there is nothing to watch
111
- if paths.empty?
112
- @env.ui.info(I18n.t("vagrant.rsync_auto_no_paths"))
113
- return 1
114
- end
115
-
116
- # Output to the user what paths we'll be watching
117
- paths.keys.sort.each do |path|
118
- paths[path].each do |path_opts|
119
- path_opts[:machine].ui.info(I18n.t(
120
- "vagrant.rsync_auto_path",
121
- path: path.to_s,
122
- ))
123
- end
124
- end
125
-
126
- @logger.info("Listening to paths: #{paths.keys.sort.inspect}")
127
- @logger.info("Ignoring #{ignores.length} paths:")
128
- ignores.each do |ignore|
129
- @logger.info(" -- #{ignore.to_s}")
130
- end
131
- @logger.info("Listening via: #{Listen::Adapter.select.inspect}")
132
- callback = method(:callback).to_proc.curry[paths]
133
- listopts = { ignore: ignores, force_polling: !!options[:poll] }
134
- listener = Listen.to(*paths.keys, listopts, &callback)
135
-
136
- # Create the callback that lets us know when we've been interrupted
137
- queue = Queue.new
138
- callback = lambda do
139
- # This needs to execute in another thread because Thread
140
- # synchronization can't happen in a trap context.
141
- Thread.new { queue << true }
142
- end
143
-
144
- # Run the listener in a busy block so that we can cleanly
145
- # exit once we receive an interrupt.
146
- Vagrant::Util::Busy.busy(callback) do
147
- listener.start
148
- queue.pop
149
- listener.stop if listener.state != :stopped
150
- end
151
-
152
- 0
153
- end
154
-
155
- # This is the callback that is called when any changes happen
156
- def callback(paths, modified, added, removed)
157
- @logger.info("File change callback called!")
158
- @logger.info(" - Modified: #{modified.inspect}")
159
- @logger.info(" - Added: #{added.inspect}")
160
- @logger.info(" - Removed: #{removed.inspect}")
161
-
162
- toSyncPaths = Hash.new
163
-
164
- paths.each do |hostpath, folders|
165
- changed_paths = []
166
- [modified, added, removed].each do |changed|
167
- changed.each do |listenpath|
168
- if listenpath.start_with?(hostpath)
169
- changed_paths << listenpath
170
- end
171
- end
172
- end
173
-
174
- if changed_paths.any?
175
- toSyncPaths[folders] = changed_paths
176
- end
177
- end
178
-
179
- # Sync all the folders that need to be synced
180
- toSyncPaths.each do |folders, changed_paths|
181
- folders.each do |opts|
182
- # Reload so we get the latest ID
183
- opts[:machine].reload
184
- if !opts[:machine].id || opts[:machine].id == ""
185
- # Skip since we can't get SSH info without an ID
186
- next
187
- end
188
-
189
- ssh_info = opts[:machine].ssh_info
190
- begin
191
- VagrantPlugins::RsyncOnlyChanged::RsyncHelper.rsync_single(opts[:machine], ssh_info, opts[:opts], changed_paths)
192
- rescue Vagrant::Errors::MachineGuestNotReady
193
- # Error communicating to the machine, probably a reload or
194
- # halt is happening. Just notify the user but don't fail out.
195
- opts[:machine].ui.error(I18n.t(
196
- "vagrant.rsync_communicator_not_ready_callback"))
197
- rescue Vagrant::Errors::RSyncError => e
198
- # Error executing rsync, so show an error
199
- opts[:machine].ui.error(I18n.t(
200
- "vagrant.rsync_auto_rsync_error", message: e.to_s))
201
- end
202
- end
203
- end
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
@@ -14,8 +14,6 @@ module VagrantPlugins
14
14
 
15
15
  # This initializes the internationalization strings.
16
16
  def self.setup_i18n
17
- I18n.load_path << File.expand_path("locales/en.yml", RsyncOnlyChanged.source_root)
18
- I18n.reload!
19
17
  end
20
18
 
21
19
  action_hook "startup-rsync" do |hook|
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module RsyncOnlyChanged
3
- VERSION = "0.5.0"
3
+ VERSION = "0.6.0"
4
4
  end
5
5
  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.5.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: