rb-inotify 0.8.5 → 0.8.6

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.5
1
+ 0.8.6
data/lib/rb-inotify.rb CHANGED
@@ -13,5 +13,5 @@ module INotify
13
13
  # An array containing the version number of rb-inotify.
14
14
  # The numbers in the array are the major, minor, and patch versions,
15
15
  # respectively.
16
- VERSION = [0, 8, 5]
16
+ VERSION = [0, 8, 6]
17
17
  end
@@ -40,6 +40,12 @@ module INotify
40
40
  # @return [Fixnum]
41
41
  attr_reader :fd
42
42
 
43
+ # @return [Boolean] Whether or not this Ruby implementation supports
44
+ # wrapping the native file descriptor in a Ruby IO wrapper.
45
+ def self.supports_ruby_io?
46
+ RUBY_PLATFORM !~ /java/
47
+ end
48
+
43
49
  # Creates a new {Notifier}.
44
50
  #
45
51
  # @return [Notifier]
@@ -76,7 +82,9 @@ module INotify
76
82
  # @return [IO] An IO object wrapping the file descriptor
77
83
  # @raise [NotImplementedError] if this is being called in JRuby
78
84
  def to_io
79
- raise NotImplementedError.new("INotify::Notifier#to_io is not supported under JRuby") if RUBY_PLATFORM =~ /java/
85
+ unless self.class.supports_ruby_io?
86
+ raise NotImplementedError.new("INotify::Notifier#to_io is not supported under JRuby")
87
+ end
80
88
  @io ||= IO.new(@fd)
81
89
  end
82
90
 
@@ -190,7 +198,11 @@ module INotify
190
198
  return watch(path, *((flags - [:recursive]) | rec_flags)) do |event|
191
199
  callback.call(event) if flags.include?(:all_events) || !(flags & event.flags).empty?
192
200
  next if (rec_flags & event.flags).empty? || !event.flags.include?(:isdir)
193
- watch(event.absolute_name, *flags, &callback)
201
+ begin
202
+ watch(event.absolute_name, *flags, &callback)
203
+ rescue Errno::ENOENT
204
+ # If the file has been deleted since the glob was run, we don't want to error out.
205
+ end
194
206
  end
195
207
  end
196
208
 
@@ -220,11 +232,25 @@ module INotify
220
232
  read_events.each {|event| event.callback!}
221
233
  end
222
234
 
235
+ # Close the notifier.
236
+ #
237
+ # @raise [SystemCallError] if closing the underlying file descriptor fails.
238
+ def close
239
+ return if Native.close(@fd) == 0
240
+
241
+ raise SystemCallError.new("Failed to properly close inotify socket" +
242
+ case FFI.errno
243
+ when Errno::EBADF::Errno; ": invalid or closed file descriptior"
244
+ when Errno::EIO::Errno; ": an I/O error occured"
245
+ end,
246
+ FFI.errno)
247
+ end
248
+
249
+ private
250
+
223
251
  # Blocks until there are one or more filesystem events
224
252
  # that this notifier has watchers registered for.
225
253
  # Once there are events, returns their {Event} objects.
226
- #
227
- # @private
228
254
  def read_events
229
255
  size = 64 * Native::Event.size
230
256
  tries = 1
@@ -252,21 +278,11 @@ module INotify
252
278
  events
253
279
  end
254
280
 
255
- def close
256
- return if Native.close(@fd) == 0
257
-
258
- raise SystemCallError.new("Failed to properly close inotify socket" +
259
- case FFI.errno
260
- when Errno::EBADF::Errno; ": invalid or closed file descriptior"
261
- when Errno::EIO::Errno; ": an I/O error occured"
262
- end,
263
- FFI.errno)
264
- end
265
-
266
- private
267
-
268
281
  # Same as IO#readpartial, or as close as we need.
269
282
  def readpartial(size)
283
+ # Use Ruby's readpartial if possible, to avoid blocking other threads.
284
+ return to_io.readpartial(size) if self.class.supports_ruby_io?
285
+
270
286
  tries = 0
271
287
  begin
272
288
  tries += 1
data/rb-inotify.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rb-inotify}
8
- s.version = "0.8.5"
8
+ s.version = "0.8.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Nathan Weizenbaum"]
12
- s.date = %q{2011-06-02}
12
+ s.date = %q{2011-08-02}
13
13
  s.description = %q{A Ruby wrapper for Linux's inotify, using FFI}
14
14
  s.email = %q{nex342@gmail.com}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rb-inotify
3
3
  version: !ruby/object:Gem::Version
4
- hash: 53
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 8
9
- - 5
10
- version: 0.8.5
8
+ - 6
9
+ version: 0.8.6
11
10
  platform: ruby
12
11
  authors:
13
12
  - Nathan Weizenbaum
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2011-06-02 00:00:00 -07:00
17
+ date: 2011-08-02 00:00:00 -07:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -26,7 +25,6 @@ dependencies:
26
25
  requirements:
27
26
  - - ">="
28
27
  - !ruby/object:Gem::Version
29
- hash: 11
30
28
  segments:
31
29
  - 0
32
30
  - 5
@@ -42,7 +40,6 @@ dependencies:
42
40
  requirements:
43
41
  - - ">="
44
42
  - !ruby/object:Gem::Version
45
- hash: 15
46
43
  segments:
47
44
  - 0
48
45
  - 4
@@ -85,7 +82,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
85
82
  requirements:
86
83
  - - ">="
87
84
  - !ruby/object:Gem::Version
88
- hash: 3
89
85
  segments:
90
86
  - 0
91
87
  version: "0"
@@ -94,7 +90,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
90
  requirements:
95
91
  - - ">="
96
92
  - !ruby/object:Gem::Version
97
- hash: 3
98
93
  segments:
99
94
  - 0
100
95
  version: "0"