vagrant-fsnotify 0.0.6 → 0.2.0

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: 980ee6f0ef0bbb9c668dc07cc8dea559455e3f0d
4
- data.tar.gz: 71277c09a929d9ff27e5483d7c1e3b6fbc65130b
3
+ metadata.gz: 461039d21338e7042fb005d2490fa17fc369089e
4
+ data.tar.gz: 16699e1e2d069a0e4c81ef954903a44f77e6a7cc
5
5
  SHA512:
6
- metadata.gz: 00057f278fd64d3d60244ebb6317c46d31487fc8d725b4b7afafa2001fa1408f9a82b4997799248daf7b9f4a63ba196336ea3d2b728c78a6e6064edd97d7bd9e
7
- data.tar.gz: d4400d6134353f3b2a1b0a232a875c214342e3f6728d9ed7787d6756df381994356af7077a744f2532157ab40c1156e0f253b6b442972dcafe389a5a222161e3
6
+ metadata.gz: 0626b5ee3d78752b6745f8531ed3b24a35430f34620c1a4feb9336a97ecbe78e794d5d6dff50af62f1a2c99f278ffd106a68f1f32747b90265200cf26d95d39f
7
+ data.tar.gz: e627af659185f6a19fda0436e87dcc2d44e1bccf1e3df1b0ade9fd07884028f9929eccce88237c9859897360c500090bf64d2b2e511eefeec4001ec4a16bcb50
data/AUTHORS ADDED
@@ -0,0 +1,5 @@
1
+ # This file lists all individuals having contributed content to the repository.
2
+
3
+ Adrien Kohlbecker <adrien.kohlbecker@gmail.com>
4
+ Don Morrison <github@elskwid.net>
5
+ Leandro Facchinetti <me@leafac.com>
@@ -0,0 +1,38 @@
1
+ 0.2.0 - 2015-07-14
2
+ ==================
3
+ - *Breaking change:* Minimum required Vagrant version changed to 1.7.3+
4
+ - Fixed a dependency issue with celluloid (#10, @leafac)
5
+
6
+ 0.1.1 - 2015-07-05 (yanked)
7
+ ===========================
8
+ Note: This release was yanked due to a dependency issue, see #9
9
+ - Added command synopsis (#7, @leafac)
10
+ - Fix issue with vagrant runtime dependency on celluloid (#8, @leafac)
11
+
12
+ 0.1.0 - 2015-07-05 (yanked)
13
+ ===========================
14
+ Note: This release was yanked due to a dependency issue, see #9
15
+ - *Breaking change:* Added support for forwading file addition/removal (#6, @leafac)
16
+ - Depend on `vagrant` rather than `listen` for better compatibility with upstream (#5, @leafac)
17
+ - Added documentation (#3 & #4, @leafac)
18
+
19
+ 0.0.6 - 2015-04-16
20
+ ==================
21
+ - Fix multimachine use, allow specifying which machine to target (@elskwid)
22
+
23
+ 0.0.5 - 2015-04-11
24
+ ==================
25
+ - Fix `listen` dependency
26
+
27
+ 0.0.4 - 2014-08-18
28
+ ==================
29
+ - Uses access time modification, rather than modified time
30
+
31
+ 0.0.3 - 2014-08-15
32
+ ==================
33
+ - Allow guest path overriding
34
+
35
+
36
+ 0.0.2 - 2014-08-15
37
+ ==================
38
+ - Increase the delay between changes to 2 seconds
data/Gemfile CHANGED
@@ -5,5 +5,5 @@ group :development do
5
5
  end
6
6
 
7
7
  group :plugins do
8
- gemspec
8
+ gem "vagrant-fsnotify", path: "."
9
9
  end
data/README.md CHANGED
@@ -1,4 +1,160 @@
1
1
  vagrant-fsnotify
2
2
  ================
3
3
 
4
- Forward filesystem change notifications to your Vagrant VM
4
+ Forward filesystem change notifications to your [Vagrant][vagrant] VM.
5
+
6
+ Problem
7
+ -------
8
+
9
+ Some filesystems (e.g. ext4, HFS+) have a feature of event notification.
10
+ Interested applications can subscribe and are notified when filesystem events
11
+ happen (e.g. a file was created, modified or deleted).
12
+
13
+ Applications can make use of this system to provide features such as auto-reload
14
+ or live updates. For example, [Jekyll][jekyll] regenerates the static website
15
+ and [Guard][guard] triggers a test run or a build when source files are
16
+ modified.
17
+
18
+ Unfortunately, [Vagrant][vagrant] users have a hard time making use of these
19
+ features when the application is running inside a virtual machine. When the file
20
+ is modified on the host, the event is not propagated to the guest and the
21
+ auto-reload never happens.
22
+
23
+ There are several bug reports related to this issue:
24
+
25
+ - <https://www.virtualbox.org/ticket/10660>
26
+ - <https://github.com/guard/listen/issues/53>
27
+ - <https://github.com/guard/listen/issues/57>
28
+ - <https://github.com/guard/guard/issues/269>
29
+ - <https://github.com/mitchellh/vagrant/issues/707>
30
+
31
+ There are two generally accepted solutions. The first is fall back to long
32
+ polling, the other is to
33
+ [forward the events over TCP][forwarding-file-events-over-tcp]. The problem with
34
+ long polling is that it's painfully slow, especially in shared folders. The
35
+ problem with forwarding events is that it's not a general approach that works
36
+ for any application.
37
+
38
+ Solution
39
+ --------
40
+
41
+ `vagrant-fsnotify` proposes a different solution: run a process listening for
42
+ filesystem events on the host and, when a notification is received, access the
43
+ virtual machine guest and `touch` the file in there (or `touch` followed by a
44
+ `rm` in case of file removals), causing an event to be propagated on the guest
45
+ filesystem.
46
+
47
+ This leverages the speed of using real filesystem events while still being
48
+ general enough to don't require any support from applications.
49
+
50
+ Caveats
51
+ -------
52
+
53
+ Due to the nature of filesystem events and the fact that `vagrant-fsnotify` uses
54
+ `touch`, the events are triggerred back on the host a second time. To avoid
55
+ infinite loops, we add an arbitrary debounce of 2 seconds between `touch`-ing
56
+ the same file. Thus, if a file is modified on the host more than once in 2
57
+ seconds the VM will only see one notification. If the second trigger on the
58
+ host or this arbitrary debounce is unacceptable for your application,
59
+ `vagrant-fsnotify` might not be for you.
60
+
61
+ Installation
62
+ ------------
63
+
64
+ `vagrant-fsnotify` is a [Vagrant][vagrant] plugin and can be installed by
65
+ running:
66
+
67
+ ```console
68
+ $ vagrant plugin install vagrant-fsnotify
69
+ ```
70
+
71
+ [Vagrant][vagrant] version 1.5 or greater is required.
72
+
73
+ Usage
74
+ -----
75
+
76
+ ### Basic setup
77
+
78
+ In `Vagrantfile` synced folder configuration, add the `fsnotify: true`
79
+ option. For example, in order to enable `vagrant-fsnotify` for the the default
80
+ `/vagrant` shared folder, add the following:
81
+
82
+ ```ruby
83
+ config.vm.synced_folder ".", "/vagrant", fsnotify: true
84
+ ```
85
+
86
+ When the guest virtual machine is up, run the following:
87
+
88
+ ```console
89
+ $ vagrant fsnotify
90
+ ```
91
+
92
+ This starts the long running process that captures filesystem events on the host
93
+ and forwards them to the guest virtual machine.
94
+
95
+ ### Multi-VM environments
96
+
97
+ In multi-VM environments, you can specify the name of the VMs targeted by
98
+ `vagrant-fsnotify` using:
99
+
100
+ ```console
101
+ $ vagrant fsnotify <vm-name-1> <vm-name-2> ...
102
+ ```
103
+
104
+ ### Excluding files
105
+
106
+ To exclude files or directories from being watched, you can add an `:exclude`
107
+ option, which takes an array of strings (matched as a regexp against relative
108
+ paths):
109
+
110
+ ```ruby
111
+ config.vm.synced_folder ".", "/vagrant", fsnotify: true,
112
+ exclude: ["path1", "some/directory"]
113
+ ```
114
+
115
+ This will exclude all files inside the `path1` and `some/directory`. It will
116
+ also exclude files such as `another/directory/path1`
117
+
118
+ ### Guest path override
119
+
120
+ If your actual path on the VM is not the same as the one in `synced_folder`, for
121
+ example when using [`vagrant-bindfs`][vagrant-bindfs], you can use the
122
+ `:override_guestpath` option:
123
+
124
+ ```ruby
125
+ config.vm.synced_folder ".", "/vagrant", fsnotify: true,
126
+ override_guestpath: "/real/path"
127
+ ```
128
+
129
+ This will forward a notification on `./myfile` to `/real/path/myfile` instead of
130
+ `/vagrant/myfile`.
131
+
132
+ ### Select filesystem events
133
+
134
+ By default, when the `:fsnotify` key in the `Vagrantfile` is configured with
135
+ `true`, all filesystem events are forwarded to the VM (i.e. file creation,
136
+ modification and removal events). If, instead, you want to select only a few of
137
+ those events to be forwarded (e.g. you don't care about file removals), you can
138
+ use an Array of Symbols among the following options: `:added`, `:modified` and
139
+ `:removed`.
140
+
141
+ For example, to forward only added files events to the default `/vagrant`
142
+ folder, add the following to the `Vagrantfile`:
143
+
144
+ ```ruby
145
+ config.vm.synced_folder ".", "/vagrant", fsnotify: [:added]
146
+ ```
147
+
148
+
149
+ Original work
150
+ -------------
151
+
152
+ This plugin used [`vagrant-rsync-back`][vagrant-rsync-back] by @smerill and the
153
+ [Vagrant][vagrant] source code as a starting point.
154
+
155
+ [vagrant]: https://www.vagrantup.com/
156
+ [jekyll]: http://jekyllrb.com/
157
+ [guard]: http://guardgem.org/
158
+ [forwarding-file-events-over-tcp]: https://github.com/guard/listen#forwarding-file-events-over-tcp
159
+ [vagrant-bindfs]: https://github.com/gael-ian/vagrant-bindfs
160
+ [vagrant-rsync-back]: https://github.com/smerrill/vagrant-rsync-back
@@ -4,6 +4,10 @@ module VagrantPlugins::Fsnotify
4
4
  class Command < Vagrant.plugin("2", :command)
5
5
  include Vagrant::Action::Builtin::MixinSyncedFolders
6
6
 
7
+ def self.synopsis
8
+ 'forwards filesystem events to virtual machine'
9
+ end
10
+
7
11
  def execute
8
12
  @logger = Log4r::Logger.new("vagrant::commands::fsnotify")
9
13
 
@@ -29,7 +33,19 @@ module VagrantPlugins::Fsnotify
29
33
 
30
34
  folder.each do |id, opts|
31
35
 
32
- next if not opts[:fsnotify]
36
+ if !(
37
+ (opts[:fsnotify] == true) ||
38
+ (
39
+ opts[:fsnotify].respond_to?(:include?) &&
40
+ (
41
+ opts[:fsnotify].include?(:modified) ||
42
+ opts[:fsnotify].include?(:added) ||
43
+ opts[:fsnotify].include?(:removed)
44
+ )
45
+ )
46
+ )
47
+ next
48
+ end
33
49
 
34
50
  # Folder info
35
51
  hostpath = opts[:hostpath]
@@ -68,7 +84,27 @@ module VagrantPlugins::Fsnotify
68
84
  end
69
85
 
70
86
  if paths.empty?
71
- @env.ui.info("Nothing to sync, exiting...")
87
+ @env.ui.info(<<-MESSAGE)
88
+ Nothing to sync.
89
+
90
+ Note that the valid values for the `:fsnotify' configuration key on
91
+ `Vagrantfile' are either `true' (which forwards all kinds of filesystem events)
92
+ or an Array containing symbols among the following options: `:modified',
93
+ `:added' and `:removed' (in which case, only the specified filesystem events are
94
+ forwarded).
95
+
96
+ For example, to forward all filesystem events to the default `/vagrant' folder,
97
+ add the following to the `Vagrantfile':
98
+
99
+ config.vm.synced_folder ".", "/vagrant", fsnotify: true
100
+
101
+ And to forward only added files events to the default `/vagrant' folder, add the
102
+ following to the `Vagrantfile':
103
+
104
+ config.vm.synced_folder ".", "/vagrant", fsnotify: [:added]
105
+
106
+ Exiting...
107
+ MESSAGE
72
108
  return 1
73
109
  end
74
110
 
@@ -95,7 +131,7 @@ module VagrantPlugins::Fsnotify
95
131
  Vagrant::Util::Busy.busy(callback) do
96
132
  listener.start
97
133
  queue.pop
98
- listener.stop if listener.listen?
134
+ listener.stop if listener.state != :stopped
99
135
  end
100
136
 
101
137
  return 0
@@ -113,10 +149,26 @@ module VagrantPlugins::Fsnotify
113
149
  end
114
150
 
115
151
  tosync = {}
152
+ todelete = []
116
153
 
117
154
  paths.each do |hostpath, folder|
118
155
 
119
- modified.each do |file|
156
+ toanalyze = []
157
+ if folder[:opts][:fsnotify] == true
158
+ toanalyze += modified + added + removed
159
+ else
160
+ if folder[:opts][:fsnotify].include? :modified
161
+ toanalyze += modified
162
+ end
163
+ if folder[:opts][:fsnotify].include? :added
164
+ toanalyze += added
165
+ end
166
+ if folder[:opts][:fsnotify].include? :removed
167
+ toanalyze += removed
168
+ end
169
+ end
170
+
171
+ toanalyze.each do |file|
120
172
 
121
173
  if file.start_with?(hostpath)
122
174
 
@@ -128,7 +180,13 @@ module VagrantPlugins::Fsnotify
128
180
  end
129
181
 
130
182
  @changes[rel_path] = Time.now.to_i
131
- folder[:machine].ui.info("fsnotify: Changed: #{rel_path}")
183
+ if modified.include? file
184
+ folder[:machine].ui.info("fsnotify: Changed: #{rel_path}")
185
+ elsif added.include? file
186
+ folder[:machine].ui.info("fsnotify: Added: #{rel_path}")
187
+ elsif removed.include? file
188
+ folder[:machine].ui.info("fsnotify: Removed: #{rel_path}")
189
+ end
132
190
 
133
191
  guestpath = folder[:opts][:override_guestpath] || folder[:opts][:guestpath]
134
192
  guestpath = File.join(guestpath, rel_path)
@@ -136,6 +194,9 @@ module VagrantPlugins::Fsnotify
136
194
  tosync[folder[:machine]] = [] if !tosync.has_key?(folder[:machine])
137
195
  tosync[folder[:machine]] << guestpath
138
196
 
197
+ if removed.include? file
198
+ todelete << guestpath
199
+ end
139
200
  end
140
201
 
141
202
  end
@@ -144,6 +205,10 @@ module VagrantPlugins::Fsnotify
144
205
 
145
206
  tosync.each do |machine, files|
146
207
  machine.communicate.execute("touch -a '#{files.join("' '")}'")
208
+ remove_from_this_machine = files & todelete
209
+ unless remove_from_this_machine.empty?
210
+ machine.communicate.execute("rm -rf '#{remove_from_this_machine.join("' '")}'")
211
+ end
147
212
  end
148
213
 
149
214
  rescue => e
@@ -4,8 +4,12 @@ rescue LoadError
4
4
  raise "The vagrant-fsnotify plugin must be run within Vagrant."
5
5
  end
6
6
 
7
- if Vagrant::VERSION < "1.5"
8
- raise "The vagrant-fsnotify plugin is only compatible with Vagrant 1.5+"
7
+ if Vagrant::VERSION < "1.7.3"
8
+ raise <<-ERROR
9
+ The vagrant-fsnotify plugin is only compatible with Vagrant 1.7.3+. If you can't
10
+ upgrade, consider installing an old version of vagrant-fsnotify with:
11
+ $ vagrant plugin install vagrant-fsnotify --plugin-version 0.0.6.
12
+ ERROR
9
13
  end
10
14
 
11
15
  module VagrantPlugins::Fsnotify
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module Fsnotify
3
- VERSION = "0.0.6"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -18,8 +18,6 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "listen", "2.8.0"
22
-
23
- spec.add_development_dependency "bundler", "~> 1.9"
24
- spec.add_development_dependency "rake", "~> 10.0"
21
+ spec.add_development_dependency "bundler"
22
+ spec.add_development_dependency "rake"
25
23
  end
metadata CHANGED
@@ -1,57 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-fsnotify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrien Kohlbecker
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-04-15 00:00:00.000000000 Z
11
+ date: 2015-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: listen
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - '='
18
- - !ruby/object:Gem::Version
19
- version: 2.8.0
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - '='
25
- - !ruby/object:Gem::Version
26
- version: 2.8.0
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: bundler
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
- - - ~>
17
+ - - ">="
32
18
  - !ruby/object:Gem::Version
33
- version: '1.9'
19
+ version: '0'
34
20
  type: :development
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
- - - ~>
24
+ - - ">="
39
25
  - !ruby/object:Gem::Version
40
- version: '1.9'
26
+ version: '0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rake
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
- - - ~>
31
+ - - ">="
46
32
  - !ruby/object:Gem::Version
47
- version: '10.0'
33
+ version: '0'
48
34
  type: :development
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
- - - ~>
38
+ - - ">="
53
39
  - !ruby/object:Gem::Version
54
- version: '10.0'
40
+ version: '0'
55
41
  description: Use vagrant-fsnotify to forward filesystem change notifications to your
56
42
  Vagrant VM
57
43
  email:
@@ -60,7 +46,9 @@ executables: []
60
46
  extensions: []
61
47
  extra_rdoc_files: []
62
48
  files:
63
- - .gitignore
49
+ - ".gitignore"
50
+ - AUTHORS
51
+ - CHANGELOG.md
64
52
  - Gemfile
65
53
  - LICENSE
66
54
  - README.md
@@ -83,17 +71,17 @@ require_paths:
83
71
  - lib
84
72
  required_ruby_version: !ruby/object:Gem::Requirement
85
73
  requirements:
86
- - - '>='
74
+ - - ">="
87
75
  - !ruby/object:Gem::Version
88
76
  version: '0'
89
77
  required_rubygems_version: !ruby/object:Gem::Requirement
90
78
  requirements:
91
- - - '>='
79
+ - - ">="
92
80
  - !ruby/object:Gem::Version
93
81
  version: '0'
94
82
  requirements: []
95
83
  rubyforge_project:
96
- rubygems_version: 2.0.14
84
+ rubygems_version: 2.4.8
97
85
  signing_key:
98
86
  specification_version: 4
99
87
  summary: Forward filesystem change notifications to your Vagrant VM