vagrant-syncer 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3cd47298b3567673c6995d30964b20fa04a75ec5
4
- data.tar.gz: 8e90c5516f9fae57e14075c575026207861fc3da
3
+ metadata.gz: 4606a84f0d691da9082851967ad17811c7cf46f8
4
+ data.tar.gz: 36204705489f9ebf80e7e61926a6d1a15b0ec964
5
5
  SHA512:
6
- metadata.gz: f9751e15a8daa2674c6c2a52332fafcd59aa1241d6291ffe76536aba6def684a01a7ae763dbfb270a64ff5f0140223c3459028cef0b93a5bda4f7f831ad700fd
7
- data.tar.gz: 4778d39d2bbb111510d3470ee6f76619223a4a40dc5d26035f07e245e9cbe7ad9dbbe550d5290ead1817f1f81cb36e247a219413b7c6e27a992e774657cc3573
6
+ metadata.gz: 2e8a4c2988e646cac0f1ad234874dd8114db70e739cd0ed27b4e304bdb4ebf3f24ab079a5074538bd551e44375838908df862c3774b2d3b8351526567fcba14d
7
+ data.tar.gz: 355ecbaa298e57d31c0654a08e6448c436d817af15c657d9c7b48c6ce121a183a8c70d4b89ea62e780c1950111b8c0c59c29666139935a3eb11efa97286781b2
data/README.md CHANGED
@@ -5,8 +5,8 @@ A Vagrant synced folder plugin that is an optimized implementation of [Vagrant r
5
5
  Vagrant syncer forks [Vagrant's RsyncHelper](https://github.com/mitchellh/vagrant/blob/b721eb62cfbfa93895d0d4cf019436ab6b1df05d/plugins/synced_folders/rsync/helper.rb)
6
6
  to make it (c)leaner, instead of using the class like [vagrant-gatling-rsync](https://github.com/smerrill/vagrant-gatling-rsync) does.
7
7
 
8
- If the optimizations seem to work in heavy use, I'll see if (some of) them
9
- can be merged to Vagrant core and be submitted as pull requests to
8
+ If the optimizations seem to work in heavy use, I'll see if (some of) them can
9
+ be merged to Vagrant core and be submitted as pull requests to
10
10
  [the official Vagrant repo](https://github.com/mitchellh/vagrant).
11
11
 
12
12
 
@@ -21,17 +21,22 @@ All the [rsync synced folder settings](https://docs.vagrantup.com/v2/synced-fold
21
21
  are supported. They also have the same default values.
22
22
 
23
23
  See [the example Vagrantfile](https://github.com/asyrjasalo/vagrant-syncer/blob/master/example/Vagrantfile)
24
- for additional plugin specific ```config.syncer``` settings and their default values.
24
+ for additional plugin specific ```config.syncer``` settings and their default
25
+ values.
25
26
 
26
27
 
27
28
  ## Usage
28
29
 
29
- vagrant syncer
30
+ The plugin replaces the following stock commands:
30
31
 
31
- ## Improvements over rsync(-auto)
32
+ vagrant rsync
33
+ vagrant rsync-auto
34
+
35
+ ## Improvements over the stock commands
32
36
 
33
37
  - The plugin has leaner rsync implementation with most of the rsync command
34
- argument constructing already handled in the class initializer and not sync-time
38
+ argument constructing already handled in the class initializer and not
39
+ sync-time
35
40
  - Uses [rb-fsevent](https://github.com/thibaudgg/rb-fsevent) and
36
41
  [rb-inotify](https://github.com/nex3/rb-inotify) gems underneath for
37
42
  performance on OS X and GNU/Linux respectively, instead of using Listen.
@@ -39,8 +44,8 @@ for additional plugin specific ```config.syncer``` settings and their default va
39
44
  - Allow defining additional SSH arguments to rsync in Vagrantfile using
40
45
  ```config.syncer.ssh_args```. This can be used for e.g. disabling SSH
41
46
  compression to lower CPU overhead.
42
- - Runs ```vagrant syncer``` to start watching changes after vagrant up, reload
43
- and resume, if ```config.syncer.run_on_startup``` set to ```true```
47
+ - Runs ```vagrant rsync-auto``` to start watching changes after vagrant up,
48
+ reload and resume, if ```config.syncer.run_on_startup``` set to ```true```
44
49
  in Vagrantfile
45
50
  - Vagrant's implementation assumes that the primary group of the SSH user
46
51
  has the same name as the user, if rsync option ```group``` is not explicitly
@@ -60,12 +65,12 @@ Fork this repository, clone it and install Ruby 2.2.3, using e.g. [rbenv](https:
60
65
 
61
66
  Then use it with:
62
67
 
63
- bundle exec vagrant syncer
68
+ bundle exec vagrant rsync-auto
64
69
 
65
70
  Or outside the bundle:
66
71
 
67
72
  ./build_and_install.sh
68
- vagrant syncer
73
+ vagrant rsync-auto
69
74
 
70
75
  I'll kindly take pull requests as well.
71
76
 
@@ -12,9 +12,9 @@ module Vagrant
12
12
 
13
13
  return unless env[:machine].config.syncer.run_on_startup
14
14
 
15
- # If Vagrant up/reload/resume exited successfully, run this syncer
15
+ # If Vagrant up/reload/resume exited successfully, run this rsync-auto
16
16
  at_exit do
17
- env[:machine].env.cli("syncer") if $!.status == 0
17
+ env[:machine].env.cli("rsync-auto") if $!.status == 0
18
18
  end
19
19
  end
20
20
  end
@@ -0,0 +1,61 @@
1
+ require 'optparse'
2
+
3
+ require "vagrant/action/builtin/mixin_synced_folders"
4
+
5
+
6
+ module Vagrant
7
+ module Syncer
8
+ module Command
9
+ class Rsync < Vagrant.plugin(2, :command)
10
+
11
+ include Vagrant::Action::Builtin::MixinSyncedFolders
12
+
13
+ def self.synopsis
14
+ "syncs rsync synced folders to remote machine"
15
+ end
16
+
17
+ def execute
18
+ opts = OptionParser.new do |o|
19
+ o.banner = "Usage: vagrant rsync [vm-name]"
20
+ o.separator ""
21
+ o.separator "This command forces any synced folders with type 'rsync' to sync."
22
+ o.separator "RSync is not an automatic sync so a manual command is used."
23
+ o.separator ""
24
+ o.separator "Options:"
25
+ o.separator ""
26
+ end
27
+
28
+ # Parse the options and return if we don't have any target.
29
+ argv = parse_options(opts)
30
+ return if !argv
31
+
32
+ # Go through each machine and perform the rsync
33
+ error = false
34
+ with_target_vms(argv) do |machine|
35
+ if machine.provider.capability?(:proxy_machine)
36
+ proxy = machine.provider.capability(:proxy_machine)
37
+ if proxy
38
+ machine.ui.warn(I18n.t(
39
+ "vagrant.rsync_proxy_machine",
40
+ name: machine.name.to_s,
41
+ provider: machine.provider_name.to_s))
42
+
43
+ machine = proxy
44
+ end
45
+ end
46
+
47
+ if !machine.communicate.ready?
48
+ machine.ui.error(I18n.t("vagrant.rsync_communicator_not_ready"))
49
+ error = true
50
+ next
51
+ end
52
+
53
+ Machine.new(machine).full_sync
54
+ end
55
+
56
+ return error ? 1 : 0
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,62 @@
1
+ require "log4r"
2
+ require 'optparse'
3
+
4
+ require "vagrant/action/builtin/mixin_synced_folders"
5
+ require "vagrant/util/platform"
6
+
7
+
8
+ # This is to avoid a bug in nio 1.0.0. Remove around nio 1.0.1
9
+ ENV["NIO4R_PURE"] = "1" if Vagrant::Util::Platform.windows?
10
+
11
+ module Vagrant
12
+ module Syncer
13
+ module Command
14
+ class RsyncAuto < Vagrant.plugin("2", :command)
15
+ include Vagrant::Action::Builtin::MixinSyncedFolders
16
+
17
+ def self.synopsis
18
+ "syncs rsync synced folders automatically when files change"
19
+ end
20
+
21
+ def execute
22
+ @logger = Log4r::Logger.new("vagrant::commands::rsync-auto")
23
+
24
+ options = {}
25
+ opts = OptionParser.new do |o|
26
+ o.banner = "Usage: vagrant rsync-auto [vm-name]"
27
+ o.separator ""
28
+ o.separator "Options:"
29
+ o.separator ""
30
+
31
+ o.on("--[no-]poll", "Force polling filesystem (slow)") do |poll|
32
+ options[:poll] = poll
33
+ end
34
+ end
35
+
36
+ # Parse the options and return if we don't have any target.
37
+ argv = parse_options(opts)
38
+ return if !argv
39
+
40
+ # Build up the paths that we need to listen to.
41
+ with_target_vms(argv) do |machine|
42
+ if machine.provider.capability?(:proxy_machine)
43
+ proxy = machine.provider.capability(:proxy_machine)
44
+ if proxy
45
+ machine.ui.warn(I18n.t(
46
+ "vagrant.rsync_proxy_machine",
47
+ name: machine.name.to_s,
48
+ provider: machine.provider_name.to_s))
49
+
50
+ machine = proxy
51
+ end
52
+ end
53
+
54
+ machine = Machine.new(machine, options[:poll])
55
+ machine.full_sync
56
+ machine.listen
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -6,14 +6,19 @@ module Vagrant
6
6
 
7
7
  include Vagrant::Action::Builtin::MixinSyncedFolders
8
8
 
9
- def initialize(machine)
9
+ def initialize(machine, polling=false)
10
10
  @paths = []
11
11
 
12
- synced_folders = synced_folders(machine)[:rsync]
13
- return unless synced_folders
12
+ cached = synced_folders(machine, cached: true)
13
+ fresh = synced_folders(machine)
14
+ diff = synced_folders_diff(cached, fresh)
15
+ if !diff[:added].empty?
16
+ machine.ui.warn(I18n.t("vagrant.rsync_auto_new_folders"))
17
+ end
14
18
 
15
- synced_folders.each do |id, folder_opts|
16
- @paths << Path.new(folder_opts, machine)
19
+ folders = cached[:rsync]
20
+ folders.each do |id, folder_opts|
21
+ @paths << Path.new(folder_opts, machine, polling)
17
22
  end
18
23
  end
19
24
 
@@ -27,4 +32,4 @@ module Vagrant
27
32
 
28
33
  end
29
34
  end
30
- end
35
+ end
data/lib/syncer/path.rb CHANGED
@@ -6,33 +6,40 @@ module Vagrant
6
6
  module Syncer
7
7
  class Path
8
8
 
9
- def initialize(path_opts, machine)
9
+ def initialize(path_opts, machine, listener_polling=false)
10
10
  @logger = machine.ui
11
11
  @source_path = path_opts[:hostpath]
12
12
  @syncer = Syncers::Rsync.new(path_opts, machine)
13
13
  @absolute_path = File.expand_path(@source_path, machine.env.root_path)
14
14
 
15
+ @listener_polling = listener_polling
15
16
  @listener_verbose = machine.config.syncer.show_events
16
17
  @listener_interval = machine.config.syncer.interval
17
18
 
18
- case Vagrant::Util::Platform.platform
19
- when /darwin/
20
- require_relative 'listeners/fsevents'
21
- @listener_class = Vagrant::Syncer::Listeners::FSEvents
22
- when /linux/
23
- require_relative 'listeners/inotify'
24
- @listener_class = Vagrant::Syncer::Listeners::INotify
25
- else
19
+ listener_settings = {
20
+ latency: @listener_interval
21
+ }
22
+
23
+ if @listener_polling
26
24
  require_relative 'listeners/listen'
27
25
  @listener_class = Vagrant::Syncer::Listeners::Listen
26
+ listener_settings[:force_polling] = @listener_polling
27
+ else
28
+ case Vagrant::Util::Platform.platform
29
+ when /darwin/
30
+ require_relative 'listeners/fsevents'
31
+ @listener_class = Vagrant::Syncer::Listeners::FSEvents
32
+ when /linux/
33
+ require_relative 'listeners/inotify'
34
+ @listener_class = Vagrant::Syncer::Listeners::INotify
35
+ else
36
+ require_relative 'listeners/listen'
37
+ @listener_class = Vagrant::Syncer::Listeners::Listen
38
+ end
28
39
  end
29
40
 
30
41
  @listener_name = @listener_class.to_s.gsub(/^.*::/, '')
31
42
 
32
- listener_settings = {
33
- latency: @listener_interval
34
- }
35
-
36
43
  @listener = @listener_class.new(
37
44
  @absolute_path,
38
45
  path_opts[:rsync__excludes],
@@ -47,7 +54,8 @@ module Vagrant
47
54
  end
48
55
 
49
56
  def listen
50
- @logger.info(I18n.t('syncer.states.watching', {
57
+ text = @listener_polling ? 'syncer.states.polling' : 'syncer.states.watching'
58
+ @logger.info(I18n.t(text, {
51
59
  path: @absolute_path,
52
60
  listener: @listener_name,
53
61
  interval: @listener_interval
@@ -68,4 +76,4 @@ module Vagrant
68
76
 
69
77
  end
70
78
  end
71
- end
79
+ end
data/lib/syncer/plugin.rb CHANGED
@@ -13,9 +13,19 @@ module Vagrant
13
13
  Vagrant::Syncer::Config
14
14
  end
15
15
 
16
- command "syncer" do
17
- require 'syncer/commands/syncer'
18
- Vagrant::Syncer::Commands::Syncer
16
+ command("rsync", primary: false) do
17
+ require_relative "command/rsync"
18
+ Vagrant::Syncer::Command::Rsync
19
+ end
20
+
21
+ command("rsync-auto", primary: false) do
22
+ require_relative "command/rsync_auto"
23
+ Vagrant::Syncer::Command::RsyncAuto
24
+ end
25
+
26
+ synced_folder("rsync", 5) do
27
+ require_relative "synced_folder"
28
+ SyncedFolder
19
29
  end
20
30
 
21
31
  ["machine_action_up", "machine_action_reload", "machine_action_resume"].each do |action|
@@ -0,0 +1,48 @@
1
+ require "log4r"
2
+
3
+ require "vagrant/util/which"
4
+
5
+ module Vagrant
6
+ module Syncer
7
+ class SyncedFolder < Vagrant.plugin("2", :synced_folder)
8
+ include Vagrant::Util
9
+
10
+ def initialize(*args)
11
+ super
12
+
13
+ @logger = Log4r::Logger.new("vagrant::synced_folders::rsync")
14
+ end
15
+
16
+ def usable?(machine, raise_error=false)
17
+ rsync_path = Which.which("rsync")
18
+ return true if rsync_path
19
+ return false if !raise_error
20
+ raise Vagrant::Errors::RSyncNotFound
21
+ end
22
+
23
+ def prepare(machine, folders, opts)
24
+ # Nothing is necessary to do before VM boot.
25
+ end
26
+
27
+ def enable(machine, folders, opts)
28
+ if machine.guest.capability?(:rsync_installed)
29
+ installed = machine.guest.capability(:rsync_installed)
30
+ if !installed
31
+ can_install = machine.guest.capability?(:rsync_install)
32
+ raise Vagrant::Errors::RSyncNotInstalledInGuest if !can_install
33
+ machine.ui.info I18n.t("vagrant.rsync_installing")
34
+ machine.guest.capability(:rsync_install)
35
+ end
36
+ end
37
+
38
+ ssh_info = machine.ssh_info
39
+
40
+ if ssh_info[:private_key_path].empty? && ssh_info[:password]
41
+ machine.ui.warn(I18n.t("vagrant.rsync_ssh_password"))
42
+ end
43
+
44
+ Machine.new(machine).full_sync
45
+ end
46
+ end
47
+ end
48
+ end
@@ -1,5 +1,5 @@
1
1
  module Vagrant
2
2
  module Syncer
3
- VERSION = "1.0.2"
3
+ VERSION = "1.0.3"
4
4
  end
5
5
  end
data/locales/en.yml CHANGED
@@ -1,8 +1,9 @@
1
1
  en:
2
2
  syncer:
3
3
  states:
4
- initial: "Syncing %{path} to get the target up to date."
5
- watching: "Watching %{path} for changes (via %{listener}) every %{interval} seconds."
4
+ initial: "Rsyncing %{path}"
5
+ watching: "Watching %{path} (using %{listener}) every %{interval} seconds."
6
+ polling: "Polling %{path} (using %{listener}) every %{interval} seconds."
6
7
  rsync:
7
8
  failed: "Rsync failed: %{error}"
8
9
  failed_command: "The failed command was: %{command}"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-syncer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anssi Syrjäsalo
@@ -73,7 +73,8 @@ files:
73
73
  - example/files/file.not
74
74
  - example/files/yes.txt
75
75
  - lib/syncer/actions.rb
76
- - lib/syncer/commands/syncer.rb
76
+ - lib/syncer/command/rsync.rb
77
+ - lib/syncer/command/rsync_auto.rb
77
78
  - lib/syncer/config.rb
78
79
  - lib/syncer/listeners/fsevents.rb
79
80
  - lib/syncer/listeners/inotify.rb
@@ -81,6 +82,7 @@ files:
81
82
  - lib/syncer/machine.rb
82
83
  - lib/syncer/path.rb
83
84
  - lib/syncer/plugin.rb
85
+ - lib/syncer/synced_folder.rb
84
86
  - lib/syncer/syncers/rsync.rb
85
87
  - lib/syncer/version.rb
86
88
  - lib/vagrant-syncer.rb
@@ -1,22 +0,0 @@
1
- module Vagrant
2
- module Syncer
3
- module Commands
4
- class Syncer < Vagrant.plugin(2, :command)
5
-
6
- def self.synopsis
7
- "start auto-rsyncing"
8
- end
9
-
10
- def execute
11
- with_target_vms do |machine|
12
- machine = Machine.new(machine)
13
- machine.full_sync
14
- machine.listen
15
- end
16
- 0
17
- end
18
-
19
- end
20
- end
21
- end
22
- end