listen 0.6.0 → 0.7.3

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.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,32 @@
1
+ ## 0.7.3 - February 24, 2013
2
+
3
+ ### Bug fix
4
+
5
+ - [#88] Update wdm dependency. (fixed by [@mrbinky3000][])
6
+ - [#78] Depend on latest rb-inotify. (fixed by [@mbj][])
7
+
8
+ ## 0.7.2 - January 11, 2013
9
+
10
+ ### Bug fix
11
+
12
+ - [#76] Exception on filename which is not in UTF-8. (fixed by [@piotr-sokolowski][])
13
+
14
+ ## 0.7.1 - January 6, 2013
15
+
16
+ ### Bug fix
17
+
18
+ - [#75] Default high precision off if the mtime call fails. (fixed by [@zanker][])
19
+
20
+ ## 0.7.0 - December 29, 2012
21
+
22
+ ### Bug fixes
23
+
24
+ - [#73] Rescue Errno::EOPNOTSUPP on sha1_checksum generation. (fixed by [@thibaudgg][])
25
+
26
+ ### New feature
27
+
28
+ - Add support for *BSD with rb-kqueue. ([@mat813][])
29
+
1
30
  ## 0.6.0 - November 21, 2012
2
31
 
3
32
  ### New feature
@@ -172,6 +201,9 @@
172
201
  [#62]: https://github.com/guard/listen/issues/62
173
202
  [#64]: https://github.com/guard/listen/issues/64
174
203
  [#65]: https://github.com/guard/listen/issues/65
204
+ [#73]: https://github.com/guard/listen/issues/73
205
+ [#75]: https://github.com/guard/listen/issues/75
206
+ [#76]: https://github.com/guard/listen/issues/76
175
207
  [@Maher4Ever]: https://github.com/Maher4Ever
176
208
  [@dkubb]: https://github.com/dkubb
177
209
  [@ebroder]: https://github.com/ebroder
@@ -180,9 +212,11 @@
180
212
  [@daemonza]: https://github.com/daemonza
181
213
  [@fny]: https://github.com/fny
182
214
  [@markiz]: https://github.com/markiz
215
+ [@mat813]: https://github.com/mat813
183
216
  [@napcs]: https://github.com/napcs
184
217
  [@netzpirat]: https://github.com/netzpirat
185
218
  [@nex3]: https://github.com/nex3
219
+ [@piotr-sokolowski]: https://github.com/piotr-sokolowski
186
220
  [@rymai]: https://github.com/rymai
187
221
  [@scottdavis]: https://github.com/scottdavis
188
222
  [@sunaku]: https://github.com/sunaku
@@ -190,4 +224,5 @@
190
224
  [@thibaudgg]: https://github.com/thibaudgg
191
225
  [@tarsolya]: https://github.com/tarsolya
192
226
  [@vongruenigen]: https://github.com/vongruenigen
227
+ [@zanker]: https://github.com/zanker
193
228
  [WDM]: https://github.com/Maher4Ever/wdm
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012 Thibaud Guillaume-Gentil
1
+ Copyright (c) 2013 Thibaud Guillaume-Gentil
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -6,7 +6,7 @@ The Listen gem listens to file modifications and notifies you about the changes.
6
6
 
7
7
  * Works everywhere!
8
8
  * Supports watching multiple directories from a single listener.
9
- * OS-specific adapters for Mac OS X 10.6+, Linux and Windows.
9
+ * OS-specific adapters for Mac OS X 10.6+, Linux, *BSD and Windows.
10
10
  * Automatic fallback to polling if OS-specific adapter doesn't work.
11
11
  * Detects file modification, addition and removal.
12
12
  * Checksum comparison for modifications made under the same second.
@@ -242,7 +242,7 @@ block execution. See the "Block API" section for an example.
242
242
  ## Listen adapters
243
243
 
244
244
  The Listen gem has a set of adapters to notify it when there are changes.
245
- There are 3 OS-specific adapters to support Mac, Linux and Windows. These adapters are fast
245
+ There are 3 OS-specific adapters to support Mac, Linux, *BSD and Windows. These adapters are fast
246
246
  as they use some system-calls to implement the notifying function.
247
247
 
248
248
  There is also a polling adapter which is a cross-platform adapter and it will
@@ -287,6 +287,7 @@ For questions please join us in our [Google group](http://groups.google.com/grou
287
287
  * [Michael Kessler (netzpirat)][] for having written the [initial specs](https://github.com/guard/listen/commit/1e457b13b1bb8a25d2240428ce5ed488bafbed1f).
288
288
  * [Travis Tilley (ttilley)][] for this awesome work on [fssm][] & [rb-fsevent][].
289
289
  * [Nathan Weizenbaum (nex3)][] for [rb-inotify][], a thorough inotify wrapper.
290
+ * [Mathieu Arnold (mat813)][] for [rb-kqueue][], a simple kqueue wrapper.
290
291
  * [stereobooster][] for [rb-fchange][], windows support wouldn't exist without him.
291
292
  * [Yehuda Katz (wycats)][] for [vigilo][], that has been a great source of inspiration.
292
293
 
@@ -305,6 +306,7 @@ For questions please join us in our [Google group](http://groups.google.com/grou
305
306
  [Travis Tilley (ttilley)]: https://github.com/ttilley
306
307
  [fssm]: https://github.com/ttilley/fssm
307
308
  [rb-fsevent]: https://github.com/thibaudgg/rb-fsevent
309
+ [Mathieu Arnold (mat813)]: https://github.com/mat813
308
310
  [Nathan Weizenbaum (nex3)]: https://github.com/nex3
309
311
  [rb-inotify]: https://github.com/nex3/rb-inotify
310
312
  [stereobooster]: https://github.com/stereobooster
@@ -45,6 +45,8 @@ module Listen
45
45
  return Adapters::Darwin.new(directories, options, &callback)
46
46
  elsif Adapters::Linux.usable_and_works?(directories, options)
47
47
  return Adapters::Linux.new(directories, options, &callback)
48
+ elsif Adapters::BSD.usable_and_works?(directories, options)
49
+ return Adapters::BSD.new(directories, options, &callback)
48
50
  elsif Adapters::Windows.usable_and_works?(directories, options)
49
51
  return Adapters::Windows.new(directories, options, &callback)
50
52
  end
@@ -0,0 +1,112 @@
1
+ module Listen
2
+ module Adapters
3
+
4
+ # Listener implementation for BSD's `kqueue`.
5
+ #
6
+ class BSD < Adapter
7
+ extend DependencyManager
8
+
9
+ # Declare the adapter's dependencies
10
+ dependency 'rb-kqueue', '~> 0.2'
11
+
12
+ # Watched kqueue events
13
+ #
14
+ # @see http://www.freebsd.org/cgi/man.cgi?query=kqueue
15
+ # @see https://github.com/nex3/rb-kqueue/blob/master/lib/rb-kqueue/queue.rb
16
+ #
17
+ EVENTS = [ :delete, :write, :extend, :attrib, :link, :rename, :revoke ]
18
+
19
+ # Initializes the Adapter. See {Listen::Adapter#initialize} for
20
+ # more info.
21
+ #
22
+ def initialize(directories, options = {}, &callback)
23
+ super
24
+ @kqueue = init_kqueue
25
+ end
26
+
27
+ # Starts the adapter.
28
+ #
29
+ # @param [Boolean] blocking whether or not to block the current thread after starting
30
+ #
31
+ def start(blocking = true)
32
+ @mutex.synchronize do
33
+ return if @stop == false
34
+ super
35
+ end
36
+
37
+ @kqueue_thread = Thread.new do
38
+ until @stop
39
+ @kqueue.poll
40
+ sleep(@latency)
41
+ end
42
+ end
43
+ @poll_thread = Thread.new { poll_changed_dirs } if @report_changes
44
+
45
+ @kqueue_thread.join if blocking
46
+ end
47
+
48
+ # Stops the adapter.
49
+ #
50
+ def stop
51
+ @mutex.synchronize do
52
+ return if @stop == true
53
+ super
54
+ end
55
+
56
+ @kqueue.stop
57
+ Thread.kill(@kqueue_thread) if @kqueue_thread
58
+ @poll_thread.join if @poll_thread
59
+ end
60
+
61
+ # Checks if the adapter is usable on the current OS.
62
+ #
63
+ # @return [Boolean] whether usable or not
64
+ #
65
+ def self.usable?
66
+ return false unless RbConfig::CONFIG['target_os'] =~ /freebsd/i
67
+ super
68
+ end
69
+
70
+ private
71
+
72
+ # Initializes a kqueue Queue and adds a watcher for each files in
73
+ # the directories passed to the adapter.
74
+ #
75
+ # @return [INotify::Notifier] initialized kqueue
76
+ #
77
+ def init_kqueue
78
+ require 'find'
79
+
80
+ callback = lambda do |event|
81
+ path = event.watcher.path
82
+ @mutex.synchronize do
83
+ # kqueue watches everything, but Listen only needs the
84
+ # directory where stuffs happens.
85
+ @changed_dirs << (File.directory?(path) ? path : File.dirname(path))
86
+
87
+ # If it is a directory, and it has a write flag, it means a
88
+ # file has been added so find out which and deal with it.
89
+ # No need to check for removed file, kqueue will forget them
90
+ # when the vfs does..
91
+ if File.directory?(path) && !(event.flags & [:write]).empty?
92
+ queue = event.watcher.queue
93
+ Find.find(path) do |file|
94
+ unless queue.watchers.detect {|k,v| v.path == file.to_s}
95
+ queue.watch_file(file, *EVENTS, &callback)
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
101
+
102
+ KQueue::Queue.new.tap do |queue|
103
+ @directories.each do |directory|
104
+ Find.find(directory) do |path|
105
+ queue.watch_file(path, *EVENTS, &callback)
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
111
+ end
112
+ end
@@ -7,7 +7,7 @@ module Listen
7
7
  extend DependencyManager
8
8
 
9
9
  # Declare the adapter's dependencies
10
- dependency 'rb-fsevent', '~> 0.9.1'
10
+ dependency 'rb-fsevent', '~> 0.9'
11
11
 
12
12
  LAST_SEPARATOR_REGEX = /\/$/
13
13
 
@@ -7,7 +7,7 @@ module Listen
7
7
  extend DependencyManager
8
8
 
9
9
  # Declare the adapter's dependencies
10
- dependency 'rb-inotify', '~> 0.8.8'
10
+ dependency 'rb-inotify', '~> 0.9'
11
11
 
12
12
  # Watched inotify events
13
13
  #
@@ -9,7 +9,7 @@ module Listen
9
9
  extend DependencyManager
10
10
 
11
11
  # Declare the adapter's dependencies
12
- dependency 'wdm', '~> 0.0.3'
12
+ dependency 'wdm', '~> 0.1'
13
13
 
14
14
  # Initializes the Adapter. See {Listen::Adapter#initialize} for more info.
15
15
  #
@@ -18,7 +18,11 @@ module Listen
18
18
  # Defines the used precision based on the type of mtime returned by the
19
19
  # system (whether its in milliseconds or just seconds)
20
20
  #
21
- HIGH_PRECISION_SUPPORTED = File.mtime(__FILE__).to_f.to_s[-2..-1] != '.0'
21
+ begin
22
+ HIGH_PRECISION_SUPPORTED = File.mtime(__FILE__).to_f.to_s[-2..-1] != '.0'
23
+ rescue
24
+ HIGH_PRECISION_SUPPORTED = false
25
+ end
22
26
 
23
27
  # Data structure used to save meta data about a path
24
28
  #
@@ -185,6 +189,7 @@ module Listen
185
189
  #
186
190
  def relative_to_base(path)
187
191
  return nil unless path[@directory]
192
+ path = path.force_encoding("BINARY") if path.respond_to?(:force_encoding)
188
193
  path.sub(%r{^#{Regexp.quote(@directory)}#{File::SEPARATOR}?}, '')
189
194
  end
190
195
 
@@ -304,7 +309,7 @@ module Listen
304
309
  #
305
310
  def sha1_checksum(path)
306
311
  Digest::SHA1.file(path).to_s
307
- rescue Errno::EACCES, Errno::ENOENT, Errno::ENXIO
312
+ rescue Errno::EACCES, Errno::ENOENT, Errno::ENXIO, Errno::EOPNOTSUPP
308
313
  nil
309
314
  end
310
315
 
@@ -1,3 +1,3 @@
1
1
  module Listen
2
- VERSION = '0.6.0'
2
+ VERSION = '0.7.3'
3
3
  end
data/lib/listen.rb CHANGED
@@ -10,6 +10,7 @@ module Listen
10
10
  module Adapters
11
11
  autoload :Darwin, 'listen/adapters/darwin'
12
12
  autoload :Linux, 'listen/adapters/linux'
13
+ autoload :BSD, 'listen/adapters/bsd'
13
14
  autoload :Windows, 'listen/adapters/windows'
14
15
  autoload :Polling, 'listen/adapters/polling'
15
16
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: listen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-11-21 00:00:00.000000000 Z
13
+ date: 2013-02-24 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -37,17 +37,18 @@ executables: []
37
37
  extensions: []
38
38
  extra_rdoc_files: []
39
39
  files:
40
- - lib/listen/adapter.rb
40
+ - lib/listen/dependency_manager.rb
41
+ - lib/listen/version.rb
41
42
  - lib/listen/adapters/darwin.rb
43
+ - lib/listen/adapters/bsd.rb
42
44
  - lib/listen/adapters/linux.rb
43
45
  - lib/listen/adapters/polling.rb
44
46
  - lib/listen/adapters/windows.rb
45
- - lib/listen/dependency_manager.rb
46
47
  - lib/listen/directory_record.rb
47
- - lib/listen/listener.rb
48
48
  - lib/listen/multi_listener.rb
49
49
  - lib/listen/turnstile.rb
50
- - lib/listen/version.rb
50
+ - lib/listen/listener.rb
51
+ - lib/listen/adapter.rb
51
52
  - lib/listen.rb
52
53
  - CHANGELOG.md
53
54
  - LICENSE
@@ -66,7 +67,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
66
67
  version: '0'
67
68
  segments:
68
69
  - 0
69
- hash: -2035972010079293192
70
+ hash: -750859891
70
71
  required_rubygems_version: !ruby/object:Gem::Requirement
71
72
  none: false
72
73
  requirements:
@@ -75,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
76
  version: 1.3.6
76
77
  requirements: []
77
78
  rubyforge_project: listen
78
- rubygems_version: 1.8.23
79
+ rubygems_version: 1.8.25
79
80
  signing_key:
80
81
  specification_version: 3
81
82
  summary: Listen to file modifications