filewatch 0.0.3 → 0.1.1
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/lib/{inotify → filewatch/inotify}/emhandler.rb +3 -3
- data/lib/{inotify → filewatch/inotify}/event.rb +9 -8
- data/lib/{inotify → filewatch/inotify}/fd.rb +24 -17
- data/lib/filewatch/namespace.rb +3 -0
- data/lib/{inotify → filewatch}/stringpipeio.rb +2 -2
- data/lib/filewatch/watch.rb +25 -0
- metadata +18 -28
- data/lib/inotify/namespace.rb +0 -2
@@ -1,7 +1,7 @@
|
|
1
|
-
require "inotify/fd"
|
2
|
-
require "
|
1
|
+
require "filewatch/inotify/fd"
|
2
|
+
require "filewatch/namespace"
|
3
3
|
|
4
|
-
class Inotify::EMHandler < EventMachine::Connection
|
4
|
+
class FileWatch::Inotify::EMHandler < EventMachine::Connection
|
5
5
|
def initialize(inotify_fd, callback=nil)
|
6
6
|
@inotify = inotify_fd
|
7
7
|
@callback = callback
|
@@ -1,8 +1,8 @@
|
|
1
|
-
require "
|
2
|
-
require "inotify/fd"
|
1
|
+
require "filewatch/namespace"
|
2
|
+
require "filewatch/inotify/fd"
|
3
3
|
require "ffi"
|
4
4
|
|
5
|
-
class Inotify::Event < FFI::Struct
|
5
|
+
class FileWatch::Inotify::Event < FFI::Struct
|
6
6
|
layout :wd, :int,
|
7
7
|
:mask, :uint32,
|
8
8
|
:cookie, :uint32,
|
@@ -21,16 +21,17 @@ class Inotify::Event < FFI::Struct
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def self.from_stringpipeio(io)
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
24
|
+
# I implemented a 'string pipe' IO because normal "buffered" IO reads
|
25
|
+
# on inotify fds fails in ruby 1.9.2 because it literally calls read(2)
|
26
|
+
# with 'self.size' as the byte size to read. This causes EINVAL from
|
27
|
+
# inotify, documented thusly in inotify(7):
|
27
28
|
#
|
28
29
|
# """ The behavior when the buffer given to read(2) is too small to
|
29
30
|
# return information about the next event depends on the kernel
|
30
31
|
# version: in kernels before 2.6.21, read(2) returns 0; since
|
31
32
|
# kernel 2.6.21, read(2) fails with the error EINVAL. """
|
32
33
|
#
|
33
|
-
# Working around this
|
34
|
+
# Working around this requires implementing our own read buffering
|
34
35
|
# unless comeone clues me in on how to make ruby 1.9.2 read larger
|
35
36
|
# blocks and actually do the nice buffered IO we've all come to
|
36
37
|
# know and love.
|
@@ -66,7 +67,7 @@ class Inotify::Event < FFI::Struct
|
|
66
67
|
end
|
67
68
|
|
68
69
|
def actions
|
69
|
-
Inotify::FD::WATCH_BITS.reject do |key, bitmask|
|
70
|
+
::FileWatch::Inotify::FD::WATCH_BITS.reject do |key, bitmask|
|
70
71
|
self[:mask] & bitmask == 0
|
71
72
|
end.keys
|
72
73
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require "rubygems"
|
2
2
|
require "ffi"
|
3
|
-
require "inotify/event"
|
4
|
-
require "
|
5
|
-
require "
|
3
|
+
require "filewatch/inotify/event"
|
4
|
+
require "filewatch/namespace"
|
5
|
+
require "filewatch/stringpipeio"
|
6
6
|
|
7
|
-
class Inotify::FD
|
7
|
+
class FileWatch::Inotify::FD
|
8
8
|
include Enumerable
|
9
9
|
|
10
10
|
module CInotify
|
@@ -47,13 +47,18 @@ class Inotify::FD
|
|
47
47
|
|
48
48
|
attr_reader :fd
|
49
49
|
|
50
|
-
|
50
|
+
public
|
51
|
+
def self.can_watch?(filestat)
|
52
|
+
# TODO(sissel): implement.
|
53
|
+
end # def self.can_watch?
|
54
|
+
|
55
|
+
# Create a new FileWatch::Inotify::FD instance.
|
51
56
|
# This is the main interface you want to use for watching
|
52
57
|
# files, directories, etc.
|
53
58
|
public
|
54
59
|
def initialize
|
55
60
|
@watches = {}
|
56
|
-
@buffer =
|
61
|
+
@buffer = FileWatch::StringPipeIO.new
|
57
62
|
|
58
63
|
@fd = CInotify.inotify_init1(INOTIFY_NONBLOCK)
|
59
64
|
|
@@ -98,7 +103,7 @@ class Inotify::FD
|
|
98
103
|
# the linux man-pages project. http://www.kernel.org/doc/man-pages/ )
|
99
104
|
#
|
100
105
|
# Example:
|
101
|
-
# fd = Inotify::FD.new
|
106
|
+
# fd = FileWatch::Inotify::FD.new
|
102
107
|
# fd.watch("/tmp", :create, :delete)
|
103
108
|
# fd.watch("/var/log/messages", :modify)
|
104
109
|
public
|
@@ -138,7 +143,7 @@ class Inotify::FD
|
|
138
143
|
# TODO(sissel): Block with select.
|
139
144
|
# Will have to use FFI to call select, too.
|
140
145
|
|
141
|
-
# We
|
146
|
+
# We have to call libc's read(2) because JRuby/Java can't trivially
|
142
147
|
# be told about existing file descriptors.
|
143
148
|
loop do
|
144
149
|
bytes = CInotify.read(@fd, @jruby_read_buffer, 4096)
|
@@ -180,22 +185,24 @@ class Inotify::FD
|
|
180
185
|
# If timeout is not given, this call blocks.
|
181
186
|
# If a timeout occurs and no event was read, nil is returned.
|
182
187
|
#
|
183
|
-
# Returns nil on timeout or an Inotify::Event on success.
|
184
|
-
|
188
|
+
# Returns nil on timeout or an FileWatch::Inotify::Event on success.
|
189
|
+
private
|
185
190
|
def get(timeout_not_supported_yet=nil)
|
186
191
|
# This big 'loop' is to support pop { |event| ... } shipping each available event.
|
187
192
|
# It's not very rubyish (we should probably use Enumerable and such.
|
188
193
|
if java?
|
189
|
-
jruby_read(timeout)
|
194
|
+
#jruby_read(timeout)
|
195
|
+
jruby_read
|
190
196
|
else
|
191
|
-
normal_read(timeout)
|
197
|
+
#normal_read(timeout)
|
198
|
+
normal_read
|
192
199
|
end
|
193
200
|
|
194
201
|
# Recover any previous partial event.
|
195
202
|
if @partial
|
196
203
|
event = @partial.from_stringpipeio(@buffer)
|
197
204
|
else
|
198
|
-
event = Inotify::Event.from_stringpipeio(@buffer)
|
205
|
+
event = FileWatch::Inotify::Event.from_stringpipeio(@buffer)
|
199
206
|
return nil if event == nil
|
200
207
|
end
|
201
208
|
|
@@ -210,7 +217,7 @@ class Inotify::FD
|
|
210
217
|
|
211
218
|
# For Enumerable support
|
212
219
|
#
|
213
|
-
# Yields one Inotify::Event per iteration. If there are no more events
|
220
|
+
# Yields one FileWatch::Inotify::Event per iteration. If there are no more events
|
214
221
|
# at the this time, then this method will end.
|
215
222
|
public
|
216
223
|
def each(&block)
|
@@ -237,8 +244,8 @@ class Inotify::FD
|
|
237
244
|
public
|
238
245
|
def subscribe(handler=nil, &block)
|
239
246
|
if defined?(EventMachine) && EventMachine.reactor_running?
|
240
|
-
require "inotify/emhandler"
|
241
|
-
handler = Inotify::EMHandler if handler == nil
|
247
|
+
require "filewatch/inotify/emhandler"
|
248
|
+
handler = FileWatch::Inotify::EMHandler if handler == nil
|
242
249
|
EventMachine::watch(@fd, handler, self, block)
|
243
250
|
else
|
244
251
|
loop do
|
@@ -254,4 +261,4 @@ class Inotify::FD
|
|
254
261
|
end
|
255
262
|
end
|
256
263
|
end
|
257
|
-
end # class Inotify::FD
|
264
|
+
end # class FileWatch::Inotify::FD
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "filewatch/inotify/fd"
|
2
|
+
require "filewatch/namespace"
|
3
|
+
|
4
|
+
class FileWatch::Watch
|
5
|
+
# This class exists to wrap inotify, kqueue, periodic polling, etc,
|
6
|
+
# to provide you with a way to watch files and directories.
|
7
|
+
#
|
8
|
+
# For now, it only supports inotify.
|
9
|
+
def initialize
|
10
|
+
@inotify = FileWatch::Inotify::FD.new
|
11
|
+
end
|
12
|
+
|
13
|
+
public
|
14
|
+
def watch(path, *what_to_watch)
|
15
|
+
@inotify.watch(path, *what_to_watch)
|
16
|
+
end # def watch
|
17
|
+
|
18
|
+
def subscribe(handler=nil, &block)
|
19
|
+
@inotify.subscribe(handler, &block)
|
20
|
+
end
|
21
|
+
|
22
|
+
def each(&block)
|
23
|
+
@inotify.each(&block)
|
24
|
+
end # def each
|
25
|
+
end # class FileWatch::Watch
|
metadata
CHANGED
@@ -1,21 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filewatch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 25
|
5
4
|
prerelease:
|
6
|
-
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 3
|
10
|
-
version: 0.0.3
|
5
|
+
version: 0.1.1
|
11
6
|
platform: ruby
|
12
7
|
authors:
|
13
|
-
- Jordan Sissel
|
8
|
+
- Jordan Sissel
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
12
|
|
18
|
-
date: 2011-03-
|
13
|
+
date: 2011-03-18 00:00:00 -07:00
|
19
14
|
default_executable:
|
20
15
|
dependencies: []
|
21
16
|
|
@@ -28,39 +23,34 @@ extensions: []
|
|
28
23
|
extra_rdoc_files: []
|
29
24
|
|
30
25
|
files:
|
31
|
-
- lib/
|
32
|
-
- lib/
|
33
|
-
- lib/
|
34
|
-
- lib/inotify/
|
35
|
-
- lib/inotify/
|
26
|
+
- lib/filewatch/watch.rb
|
27
|
+
- lib/filewatch/namespace.rb
|
28
|
+
- lib/filewatch/stringpipeio.rb
|
29
|
+
- lib/filewatch/inotify/emhandler.rb
|
30
|
+
- lib/filewatch/inotify/fd.rb
|
31
|
+
- lib/filewatch/inotify/event.rb
|
36
32
|
has_rdoc: true
|
37
|
-
homepage: https://github.com/jordansissel/ruby-
|
33
|
+
homepage: https://github.com/jordansissel/ruby-filewatch
|
38
34
|
licenses: []
|
39
35
|
|
40
36
|
post_install_message:
|
41
37
|
rdoc_options: []
|
42
38
|
|
43
39
|
require_paths:
|
44
|
-
- lib
|
45
|
-
- lib
|
40
|
+
- lib
|
41
|
+
- lib
|
46
42
|
required_ruby_version: !ruby/object:Gem::Requirement
|
47
43
|
none: false
|
48
44
|
requirements:
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
segments:
|
53
|
-
- 0
|
54
|
-
version: "0"
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: "0"
|
55
48
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
49
|
none: false
|
57
50
|
requirements:
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
segments:
|
62
|
-
- 0
|
63
|
-
version: "0"
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
64
54
|
requirements: []
|
65
55
|
|
66
56
|
rubyforge_project:
|
data/lib/inotify/namespace.rb
DELETED