vagrant-rsync-only-changed 0.5.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 +7 -0
- data/.gitignore +9 -0
- data/.project +17 -0
- data/Gemfile +9 -0
- data/README.md +36 -0
- data/Rakefile +3 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/vagrant-rsync-only-changed.rb +24 -0
- data/lib/vagrant-rsync-only-changed/action/startup_rsync.rb +48 -0
- data/lib/vagrant-rsync-only-changed/command/rsync_auto.rb +208 -0
- data/lib/vagrant-rsync-only-changed/config.rb +22 -0
- data/lib/vagrant-rsync-only-changed/errors.rb +19 -0
- data/lib/vagrant-rsync-only-changed/helper.rb +200 -0
- data/lib/vagrant-rsync-only-changed/plugin.rb +40 -0
- data/lib/vagrant-rsync-only-changed/version.rb +5 -0
- data/vagrant-rsync-only-changed.gemspec +23 -0
- metadata +90 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 19b21c8078ed412f7a9f550e5d34dcbbcbc79ddc
|
4
|
+
data.tar.gz: 26ed3e283a53874f0a8b12ffb7e7cfe366279ed8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e9c41278bc21bc1a7abe11cc2dcc65b02fa7b178a54280e08aa62829bf723db25e3e1017df56b9a42bad8dfed532c881db6ff0f9ff5dd651b402e4eb44a8db49
|
7
|
+
data.tar.gz: 0a54d6abce4d152809f1fb1f6e8112c0f821241ca87c7656ae7f720f776ad77cca69e323225fe46f8d11d6706cb5a3f40886700f4cd577cd2c574ab86eff4be9
|
data/.gitignore
ADDED
data/.project
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<projectDescription>
|
3
|
+
<name>vagrant-rsync-only-changed</name>
|
4
|
+
<comment></comment>
|
5
|
+
<projects>
|
6
|
+
</projects>
|
7
|
+
<buildSpec>
|
8
|
+
<buildCommand>
|
9
|
+
<name>org.eclipse.dltk.core.scriptbuilder</name>
|
10
|
+
<arguments>
|
11
|
+
</arguments>
|
12
|
+
</buildCommand>
|
13
|
+
</buildSpec>
|
14
|
+
<natures>
|
15
|
+
<nature>org.eclipse.dltk.ruby.core.nature</nature>
|
16
|
+
</natures>
|
17
|
+
</projectDescription>
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Vagrant::Rsync::Only::Changed
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/vagrant/rsync/only/changed`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'vagrant-rsync-only-changed'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install vagrant-rsync-only-changed
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/vagrant-rsync-only-changed.
|
36
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "vagrant/rsync/only/changed"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# This file is required because Vagrant's plugin system expects
|
2
|
+
# an eponymous ruby file matching the rubygem.
|
3
|
+
#
|
4
|
+
# So this gem is called 'vagrant-gatling-rsync' and thus vagrant tries
|
5
|
+
# to require "vagrant-gatling-rsync"
|
6
|
+
|
7
|
+
require "vagrant-rsync-only-changed/plugin"
|
8
|
+
|
9
|
+
require "pathname"
|
10
|
+
|
11
|
+
module VagrantPlugins
|
12
|
+
module RsyncOnlyChanged
|
13
|
+
lib_path = Pathname.new(File.expand_path("../vagrant-rsync-only-changed", __FILE__))
|
14
|
+
autoload :Errors, lib_path.join("errors")
|
15
|
+
autoload :Errors, lib_path.join("helper")
|
16
|
+
|
17
|
+
# This returns the path to the source of this plugin.
|
18
|
+
#
|
19
|
+
# @return [Pathname]
|
20
|
+
def self.source_root
|
21
|
+
@source_root ||= Pathname.new(File.expand_path("../../", __FILE__))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require "vagrant"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module RsyncOnlyChanged
|
5
|
+
class StartupRsync
|
6
|
+
include Vagrant::Action::Builtin::MixinSyncedFolders
|
7
|
+
|
8
|
+
def initialize(app, env)
|
9
|
+
@app = app
|
10
|
+
@rsync_only_changed_startup_registered = false
|
11
|
+
@rsync_folder_count = 0
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
folders = synced_folders(env[:machine])
|
16
|
+
@rsync_folder_count += folders[:rsync].size if folders.key?(:rsync)
|
17
|
+
|
18
|
+
@app.call(env)
|
19
|
+
|
20
|
+
# Ensure only one at_exit block is registered.
|
21
|
+
return unless @rsync_only_changed_startup_registered == false
|
22
|
+
|
23
|
+
return unless env[:machine].config.gatling.rsync_on_startup == true
|
24
|
+
|
25
|
+
at_exit do
|
26
|
+
unless $!.is_a?(SystemExit)
|
27
|
+
env[:ui].warn "Vagrant's startup was interrupted by an exception."
|
28
|
+
exit 1
|
29
|
+
end
|
30
|
+
|
31
|
+
exit_status = $!.status
|
32
|
+
if exit_status != 0
|
33
|
+
env[:ui].warn "The previous process exited with exit code #{exit_status}."
|
34
|
+
exit exit_status
|
35
|
+
end
|
36
|
+
|
37
|
+
# Don't run if there are no rsynced folders.
|
38
|
+
unless @rsync_folder_count == 0 then
|
39
|
+
env[:ui].info I18n.t("vagrant_rsync-only-changed.startup_sync")
|
40
|
+
env[:machine].env.cli("rsync-auto-only-changed")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
@rsync_only_changed_startup_registered = true
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,208 @@
|
|
1
|
+
require "log4r"
|
2
|
+
require "optparse"
|
3
|
+
|
4
|
+
require "vagrant"
|
5
|
+
|
6
|
+
require "log4r"
|
7
|
+
require 'optparse'
|
8
|
+
require "thread"
|
9
|
+
|
10
|
+
require "vagrant/action/builtin/mixin_synced_folders"
|
11
|
+
require "vagrant/util/busy"
|
12
|
+
require "vagrant/util/platform"
|
13
|
+
|
14
|
+
require_relative "../helper"
|
15
|
+
|
16
|
+
# This is to avoid a bug in nio 1.0.0. Remove around nio 1.0.1
|
17
|
+
if Vagrant::Util::Platform.windows?
|
18
|
+
ENV["NIO4R_PURE"] = "1"
|
19
|
+
end
|
20
|
+
|
21
|
+
require "listen"
|
22
|
+
|
23
|
+
module VagrantPlugins
|
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
|
207
|
+
end
|
208
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "vagrant"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module RsyncOnlyChanged
|
5
|
+
class Config < Vagrant.plugin(2, :config)
|
6
|
+
attr_accessor :rsync_on_startup
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@rsync_on_startup = UNSET_VALUE
|
10
|
+
end
|
11
|
+
|
12
|
+
def finalize!
|
13
|
+
if @rsync_on_startup == UNSET_VALUE
|
14
|
+
@rsync_on_startup = true
|
15
|
+
else
|
16
|
+
@rsync_on_startup = !!@rsync_on_startup
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "vagrant"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module RsyncOnlyChanged
|
5
|
+
module Errors
|
6
|
+
class VagrantRsyncOnlyChangedError < Vagrant::Errors::VagrantError
|
7
|
+
error_namespace("vagrant_gatling_rsync.errors")
|
8
|
+
end
|
9
|
+
|
10
|
+
class OSNotSupportedError < VagrantRsyncOnlyChangedError
|
11
|
+
error_key(:os_not_supported)
|
12
|
+
end
|
13
|
+
|
14
|
+
class Vagrant15RequiredError < VagrantRsyncOnlyChangedError
|
15
|
+
error_key(:vagrant_15_required)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,200 @@
|
|
1
|
+
require "vagrant/util/platform"
|
2
|
+
require "vagrant/util/subprocess"
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module RsyncOnlyChanged
|
6
|
+
# This is a helper that abstracts out the functionality of rsyncing
|
7
|
+
# folders so that it can be called from anywhere.
|
8
|
+
class RsyncHelper
|
9
|
+
# This converts an rsync exclude pattern to a regular expression
|
10
|
+
# we can send to Listen.
|
11
|
+
def self.exclude_to_regexp(path, exclude)
|
12
|
+
start_anchor = false
|
13
|
+
|
14
|
+
if exclude.start_with?("/")
|
15
|
+
start_anchor = true
|
16
|
+
exclude = exclude[1..-1]
|
17
|
+
end
|
18
|
+
|
19
|
+
path = "#{path}/" if !path.end_with?("/")
|
20
|
+
regexp = "^#{Regexp.escape(path)}"
|
21
|
+
regexp += ".*" if !start_anchor
|
22
|
+
|
23
|
+
# This is REALLY ghetto, but its a start. We can improve and
|
24
|
+
# keep unit tests passing in the future.
|
25
|
+
exclude = exclude.gsub("**", "|||GLOBAL|||")
|
26
|
+
exclude = exclude.gsub("*", "|||PATH|||")
|
27
|
+
exclude = exclude.gsub("|||PATH|||", "[^/]*")
|
28
|
+
exclude = exclude.gsub("|||GLOBAL|||", ".*")
|
29
|
+
regexp += exclude
|
30
|
+
|
31
|
+
Regexp.new(regexp)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.adapt_path_for_rsync(root_path, path)
|
35
|
+
path = File.expand_path(path, root_path)
|
36
|
+
path = Vagrant::Util::Platform.fs_real_path(path).to_s
|
37
|
+
|
38
|
+
if Vagrant::Util::Platform.windows?
|
39
|
+
# rsync for Windows expects cygwin style paths, always.
|
40
|
+
path = Vagrant::Util::Platform.cygwin_path(path)
|
41
|
+
end
|
42
|
+
|
43
|
+
return path
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.adapt_filepath_for_rsync(root_path, filepath)
|
47
|
+
path = File.dirname(filepath)
|
48
|
+
filename = File.basename(filepath)
|
49
|
+
|
50
|
+
return adapt_path_for_rsync(root_path, path) + "/" + filename
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.rsync_single(machine, ssh_info, opts, changed_folders=[])
|
54
|
+
# Folder info
|
55
|
+
guestpath = opts[:guestpath]
|
56
|
+
hostpath = opts[:hostpath]
|
57
|
+
original_path = opts[:hostpath]
|
58
|
+
|
59
|
+
root_path = machine.env.root_path
|
60
|
+
hostpath = adapt_path_for_rsync(root_path, hostpath)
|
61
|
+
|
62
|
+
# Make sure the host path ends with a "/" to avoid creating
|
63
|
+
# a nested directory...
|
64
|
+
if !hostpath.end_with?("/")
|
65
|
+
hostpath += "/"
|
66
|
+
end
|
67
|
+
|
68
|
+
# Folder options
|
69
|
+
opts[:owner] ||= ssh_info[:username]
|
70
|
+
opts[:group] ||= ssh_info[:username]
|
71
|
+
|
72
|
+
# Connection information
|
73
|
+
username = ssh_info[:username]
|
74
|
+
host = ssh_info[:host]
|
75
|
+
proxy_command = ""
|
76
|
+
if ssh_info[:proxy_command]
|
77
|
+
proxy_command = "-o ProxyCommand='#{ssh_info[:proxy_command]}' "
|
78
|
+
end
|
79
|
+
|
80
|
+
rsh = [
|
81
|
+
"ssh -p #{ssh_info[:port]} " +
|
82
|
+
proxy_command +
|
83
|
+
"-o StrictHostKeyChecking=no " +
|
84
|
+
"-o IdentitiesOnly=true " +
|
85
|
+
"-o UserKnownHostsFile=/dev/null",
|
86
|
+
ssh_info[:private_key_path].map { |p| "-i '#{p}'" },
|
87
|
+
].flatten.join(" ")
|
88
|
+
|
89
|
+
# Exclude some files by default, and any that might be configured
|
90
|
+
# by the user.
|
91
|
+
excludes = ['.vagrant/']
|
92
|
+
excludes += Array(opts[:exclude]).map(&:to_s) if opts[:exclude]
|
93
|
+
excludes.uniq!
|
94
|
+
|
95
|
+
# Get the command-line arguments
|
96
|
+
args = nil
|
97
|
+
args = Array(opts[:args]).dup if opts[:args]
|
98
|
+
args ||= ["--verbose", "--archive", "--delete", "-z", "--copy-links"]
|
99
|
+
|
100
|
+
# On Windows, we have to set a default chmod flag to avoid permission issues
|
101
|
+
if Vagrant::Util::Platform.windows? && !args.any? { |arg| arg.start_with?("--chmod=") }
|
102
|
+
# Ensures that all non-masked bits get enabled
|
103
|
+
args << "--chmod=ugo=rwX"
|
104
|
+
|
105
|
+
# Remove the -p option if --archive is enabled (--archive equals -rlptgoD)
|
106
|
+
# otherwise new files will not have the destination-default permissions
|
107
|
+
args << "--no-perms" if args.include?("--archive") || args.include?("-a")
|
108
|
+
end
|
109
|
+
|
110
|
+
# Disable rsync's owner/group preservation (implied by --archive) unless
|
111
|
+
# specifically requested, since we adjust owner/group to match shared
|
112
|
+
# folder setting ourselves.
|
113
|
+
args << "--no-owner" unless args.include?("--owner") || args.include?("-o")
|
114
|
+
args << "--no-group" unless args.include?("--group") || args.include?("-g")
|
115
|
+
|
116
|
+
# Tell local rsync how to invoke remote rsync with sudo
|
117
|
+
rsync_path = opts[:rsync_path]
|
118
|
+
if !rsync_path && machine.guest.capability?(:rsync_command)
|
119
|
+
rsync_path = machine.guest.capability(:rsync_command)
|
120
|
+
end
|
121
|
+
if rsync_path
|
122
|
+
args << "--rsync-path"<< rsync_path
|
123
|
+
end
|
124
|
+
|
125
|
+
# Make sure the original host path ends with a "/" to create
|
126
|
+
# only relative entries in the changed files list...
|
127
|
+
if !original_path.end_with?("/")
|
128
|
+
original_path += "/"
|
129
|
+
end
|
130
|
+
|
131
|
+
# Create a file with the list of changed files/directories
|
132
|
+
if changed_folders.any?
|
133
|
+
changed_list_file = File.join(Dir.tmpdir, "rsync.#{rand(1000)}")
|
134
|
+
File.open(changed_list_file, "w+") do |f|
|
135
|
+
changed_folders.each do |folder|
|
136
|
+
rsync_folder = folder.sub(original_path, '')
|
137
|
+
|
138
|
+
#The changed file needs to be relative to the rsync root
|
139
|
+
f.puts(rsync_folder)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
args << "--files-from=" + adapt_filepath_for_rsync(root_path, changed_list_file)
|
144
|
+
end
|
145
|
+
|
146
|
+
# Build up the actual command to execute
|
147
|
+
command = [
|
148
|
+
"rsync",
|
149
|
+
args,
|
150
|
+
"-e", rsh,
|
151
|
+
excludes.map { |e| ["--exclude", e] },
|
152
|
+
hostpath,
|
153
|
+
"#{username}@#{host}:#{guestpath}",
|
154
|
+
].flatten
|
155
|
+
|
156
|
+
# The working directory should be the root path
|
157
|
+
command_opts = {}
|
158
|
+
command_opts[:workdir] = machine.env.root_path.to_s
|
159
|
+
|
160
|
+
machine.ui.info(I18n.t(
|
161
|
+
"vagrant.rsync_folder", guestpath: guestpath, hostpath: hostpath))
|
162
|
+
if excludes.length > 1
|
163
|
+
machine.ui.info(I18n.t(
|
164
|
+
"vagrant.rsync_folder_excludes", excludes: excludes.inspect))
|
165
|
+
end
|
166
|
+
if opts.include?(:verbose)
|
167
|
+
machine.ui.info(I18n.t("vagrant.rsync_showing_output"));
|
168
|
+
end
|
169
|
+
|
170
|
+
# If we have tasks to do before rsyncing, do those.
|
171
|
+
if machine.guest.capability?(:rsync_pre)
|
172
|
+
machine.guest.capability(:rsync_pre, opts)
|
173
|
+
end
|
174
|
+
|
175
|
+
if opts.include?(:verbose)
|
176
|
+
command_opts[:notify] = [:stdout, :stderr]
|
177
|
+
r = Vagrant::Util::Subprocess.execute(*(command + [command_opts])) {
|
178
|
+
|io_name,data| data.each_line { |line|
|
179
|
+
machine.ui.info("rsync[#{io_name}] -> #{line}") }
|
180
|
+
}
|
181
|
+
else
|
182
|
+
r = Vagrant::Util::Subprocess.execute(*(command + [command_opts]))
|
183
|
+
end
|
184
|
+
|
185
|
+
if r.exit_code != 0
|
186
|
+
raise Vagrant::Errors::RSyncError,
|
187
|
+
command: command.join(" "),
|
188
|
+
guestpath: guestpath,
|
189
|
+
hostpath: hostpath,
|
190
|
+
stderr: r.stderr
|
191
|
+
end
|
192
|
+
|
193
|
+
# If we have tasks to do after rsyncing, do those.
|
194
|
+
if machine.guest.capability?(:rsync_post)
|
195
|
+
machine.guest.capability(:rsync_post, opts)
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
begin
|
2
|
+
require "vagrant"
|
3
|
+
rescue LoadError
|
4
|
+
raise "The Vagrant gatling rsync plugin must be run within Vagrant."
|
5
|
+
end
|
6
|
+
|
7
|
+
module VagrantPlugins
|
8
|
+
module RsyncOnlyChanged
|
9
|
+
class Plugin < Vagrant.plugin(2)
|
10
|
+
name "Rsync only the changed files and/or directories"
|
11
|
+
description <<-DESC
|
12
|
+
Rsync large project directories to your Vagrant VM without incurring the delay from the rsync filetree comparison.
|
13
|
+
DESC
|
14
|
+
|
15
|
+
# This initializes the internationalization strings.
|
16
|
+
def self.setup_i18n
|
17
|
+
I18n.load_path << File.expand_path("locales/en.yml", RsyncOnlyChanged.source_root)
|
18
|
+
I18n.reload!
|
19
|
+
end
|
20
|
+
|
21
|
+
action_hook "startup-rsync" do |hook|
|
22
|
+
setup_i18n
|
23
|
+
require_relative "action/startup_rsync"
|
24
|
+
hook.after Vagrant::Action::Builtin::SyncedFolders, StartupRsync
|
25
|
+
end
|
26
|
+
|
27
|
+
command "rsync-auto-only-changed" do
|
28
|
+
setup_i18n
|
29
|
+
|
30
|
+
require_relative "command/rsync_auto"
|
31
|
+
RsyncOnlyChangedAuto
|
32
|
+
end
|
33
|
+
|
34
|
+
config "gatling" do
|
35
|
+
require_relative "config"
|
36
|
+
Config
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'vagrant-rsync-only-changed/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "vagrant-rsync-only-changed"
|
8
|
+
spec.version = VagrantPlugins::RsyncOnlyChanged::VERSION
|
9
|
+
spec.authors = ["Fl\xC3\xA1vio Botelho"]
|
10
|
+
spec.email = ["fezsentido@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Vagrant plugin to speed rsync-auto for big file trees}
|
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
|
+
spec.homepage = "https://github.com/nuncanada/vagrant-rsync-only-changed"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vagrant-rsync-only-changed
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Flávio Botelho
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Currently Vagrant rsync-auto command will always issue a full rsync when
|
42
|
+
an event is detected during rsync-auto. With this plugin rsync will be called with
|
43
|
+
the parameter --files-from with only the added/changed/removed files and/or directories
|
44
|
+
listed. This will speed up a lot the command for big file trees.
|
45
|
+
email:
|
46
|
+
- fezsentido@gmail.com
|
47
|
+
executables: []
|
48
|
+
extensions: []
|
49
|
+
extra_rdoc_files: []
|
50
|
+
files:
|
51
|
+
- ".gitignore"
|
52
|
+
- ".project"
|
53
|
+
- Gemfile
|
54
|
+
- README.md
|
55
|
+
- Rakefile
|
56
|
+
- bin/console
|
57
|
+
- bin/setup
|
58
|
+
- lib/vagrant-rsync-only-changed.rb
|
59
|
+
- lib/vagrant-rsync-only-changed/action/startup_rsync.rb
|
60
|
+
- lib/vagrant-rsync-only-changed/command/rsync_auto.rb
|
61
|
+
- lib/vagrant-rsync-only-changed/config.rb
|
62
|
+
- lib/vagrant-rsync-only-changed/errors.rb
|
63
|
+
- lib/vagrant-rsync-only-changed/helper.rb
|
64
|
+
- lib/vagrant-rsync-only-changed/plugin.rb
|
65
|
+
- lib/vagrant-rsync-only-changed/version.rb
|
66
|
+
- vagrant-rsync-only-changed.gemspec
|
67
|
+
homepage: https://github.com/nuncanada/vagrant-rsync-only-changed
|
68
|
+
licenses: []
|
69
|
+
metadata: {}
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 2.4.5
|
87
|
+
signing_key:
|
88
|
+
specification_version: 4
|
89
|
+
summary: Vagrant plugin to speed rsync-auto for big file trees
|
90
|
+
test_files: []
|