sinotify 0.0.2
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/.gitignore +8 -0
- data/History.txt +3 -0
- data/README.rdoc +141 -0
- data/README.txt +141 -0
- data/Rakefile +72 -0
- data/TODO +12 -0
- data/examples/watcher.rb +30 -0
- data/ext/extconf.rb +12 -0
- data/ext/src/inotify-syscalls.h +24 -0
- data/ext/src/inotify.h +113 -0
- data/ext/src/sinotify.c +205 -0
- data/lib/sinotify.rb +18 -0
- data/lib/sinotify/event.rb +185 -0
- data/lib/sinotify/notifier.rb +334 -0
- data/lib/sinotify/prim_event.rb +114 -0
- data/lib/sinotify/watch.rb +21 -0
- data/lib/sinotify_info.rb +47 -0
- data/sinotify.gemspec +80 -0
- data/spec/prim_notify_spec.rb +98 -0
- data/spec/sinotify_spec.rb +265 -0
- data/spec/spec_helper.rb +14 -0
- data/tasks/ann.rake +80 -0
- data/tasks/bones.rake +20 -0
- data/tasks/gem.rake +201 -0
- data/tasks/git.rake +40 -0
- data/tasks/notes.rake +27 -0
- data/tasks/post_load.rake +34 -0
- data/tasks/rdoc.rake +51 -0
- data/tasks/rubyforge.rake +55 -0
- data/tasks/setup.rb +292 -0
- data/tasks/spec.rake +54 -0
- data/tasks/svn.rake +47 -0
- data/tasks/test.rake +40 -0
- data/tasks/zentest.rake +36 -0
- metadata +154 -0
data/.gitignore
ADDED
data/History.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
sinotify
|
2
|
+
|
3
|
+
by {Steven Swerling}[http://tab-a.slot-z.net]
|
4
|
+
|
5
|
+
{rdoc}[http://tab-a.slot-z.net] | {github}[http://www.github.com/swerling/sinotify]
|
6
|
+
|
7
|
+
== DESCRIPTION:
|
8
|
+
|
9
|
+
ALPHA Alert -- just uploaded initial release.
|
10
|
+
|
11
|
+
|
12
|
+
Linux inotify is a means to receive events describing file system activity (create, modify, delete, close, etc).
|
13
|
+
|
14
|
+
Sinotify was derived from aredridel's package (http://raa.ruby-lang.org/project/ruby-inotify/), with the addition of
|
15
|
+
Paul Boon's tweak for making the event_check thread more polite (see
|
16
|
+
http://www.mindbucket.com/2009/02/24/ruby-daemons-verifying-good-behavior/)
|
17
|
+
|
18
|
+
In sinotify, the classes Sinotify::PrimNotifier and Sinotify::PrimEvent provide a low level wrapper to inotify, with
|
19
|
+
the ability to establish 'watches' and then listen for inotify events using one of inotify's synchronous event loops,
|
20
|
+
and providing access to the events' masks (see 'man inotify' for details). Sinotify::PrimEvent class adds a little semantic sugar
|
21
|
+
to the event in to the form of 'etypes', which are just ruby symbols that describe the event mask. If the event has a
|
22
|
+
raw mask of (DELETE_SELF & IS_DIR), then the etypes array would be [:delete_self, :is_dir].
|
23
|
+
|
24
|
+
In addition to the 'straight' wrapper in inotify, sinotify provides an asynchronous implementation of the 'observer
|
25
|
+
pattern' for notification. In other words, Sinotify::Notifier listens in the background for inotify events, adapting
|
26
|
+
them into instances of Sinotify::Event as they come in and immediately placing them in a concurrent queue, from which
|
27
|
+
they are 'announced' to 'subscribers' of the event. [Sinotify uses the 'cosell' implementation of the Announcements
|
28
|
+
event notification framework, hence the terminology 'subscribe' and 'announce' rather then 'listen' and 'trigger' used
|
29
|
+
in the standard event observer pattern. See the 'cosell' package on github for details.]
|
30
|
+
|
31
|
+
A variety of 'knobs' are provided for controlling the behavior of the notifier: whether a watch should apply to a
|
32
|
+
single directory or should recurse into subdirectores, how fast it should broadcast queued events, etc (see
|
33
|
+
Sinotify::Notifier, and the example in the synopsis section below). An event 'spy' can also be setup to log all
|
34
|
+
Sinotify::PrimEvents and Sinotify::Events.
|
35
|
+
|
36
|
+
Sinotify::Event simplifies inotify's muddled event model, sending events only for those files/directories that have
|
37
|
+
changed. That's not to say you can't setup a notifier that recurses into subdirectories, just that any individual
|
38
|
+
event will apply to a single file, and not to its children. Also, event types are identified using words (in the form
|
39
|
+
of ruby :symbols) instead of inotify's event masks. See Sinotify::Event for more explanation.
|
40
|
+
|
41
|
+
The README for inotify:
|
42
|
+
|
43
|
+
http://www.kernel.org/pub/linux/kernel/people/rml/inotify/README
|
44
|
+
|
45
|
+
Selected quotes from the README for inotify:
|
46
|
+
|
47
|
+
* "Rumor is that the 'd' in 'dnotify' does not stand for 'directory' but for 'suck.'"
|
48
|
+
|
49
|
+
* "The 'i' in inotify does not stand for 'suck' but for 'inode' -- the logical
|
50
|
+
choice since inotify is inode-based."
|
51
|
+
|
52
|
+
(The 's' in 'sinotify' does in fact stand for 'suck.')
|
53
|
+
|
54
|
+
|
55
|
+
== FEATURES/PROBLEMS:
|
56
|
+
|
57
|
+
* None known. But it's still early.
|
58
|
+
|
59
|
+
== SYNOPSIS:
|
60
|
+
|
61
|
+
Try this:
|
62
|
+
|
63
|
+
$ mkdir /tmp/sinotify_test
|
64
|
+
$ irb
|
65
|
+
require 'sinotify'
|
66
|
+
notifier = Sinotify::Notifier.new('/tmp/sinotify_test', :recurse => true, :etypes => [:create, :modify, :delete])
|
67
|
+
notifier.spy!(:logger => Logger.new('/tmp/inotify_spy.log')) # optional event spy
|
68
|
+
notifier.when_announcing(Sinotify::Event) do |sinotify_event|
|
69
|
+
puts "Event happened at #{sinotify_event.timestamp} on #{sinotify_event.path}, etypes => #{sinotify_event.etypes.inspect}"
|
70
|
+
end
|
71
|
+
notifier.when_announcing(Sinotify::Event) do |sinotify_event|
|
72
|
+
puts " --> demonstrate that multiple subscribers can be setup: #{sinotify_event.etypes.inspect}"
|
73
|
+
end
|
74
|
+
notifier.watch! # don't forget to start the watch
|
75
|
+
|
76
|
+
Then in another linux console:
|
77
|
+
|
78
|
+
$ touch /tmp/sinotify_test/hi && sleep 1 && echo 'hello' >> /tmp/sinotify_test/hi && sleep 1 && rm -r /tmp/sinotify_test
|
79
|
+
|
80
|
+
Back in irb you will see:
|
81
|
+
|
82
|
+
Event happened at Sat Jul 11 12:29:18 -0400 2009 on /tmp/sinotify_test/hi, etypes => [:create]
|
83
|
+
--> demonstrate that multiple subscribers can be setup: [:create]
|
84
|
+
Event happened at Sat Jul 11 12:29:19 -0400 2009 on /tmp/sinotify_test/hi, etypes => [:modify]
|
85
|
+
--> demonstrate that multiple subscribers can be setup: [:modify]
|
86
|
+
Event happened at Sat Jul 11 12:29:20 -0400 2009 on /tmp/sinotify_test/hi, etypes => [:delete]
|
87
|
+
--> demonstrate that multiple subscribers can be setup: [:delete]
|
88
|
+
Event happened at Sat Jul 11 12:29:20 -0400 2009 on /tmp/sinotify_test, etypes => [:delete]
|
89
|
+
--> demonstrate that multiple subscribers can be setup: [:delete]
|
90
|
+
|
91
|
+
|
92
|
+
tail -n 50 -f /tmp/inotify_spy.log:
|
93
|
+
|
94
|
+
...
|
95
|
+
... INFO -- : Sinotify::Notifier Prim Event Spy: <Sinotify::PrimEvent :name => 'hi', :etypes => [:create], :mask => 100 ...
|
96
|
+
... INFO -- : Sinotify::Notifier Event Spy <Sinotify::Event :path => '/tmp/sinotify_test/hi', dir? => false, :etypes => ...
|
97
|
+
... INFO -- : Sinotify::Notifier Prim Event Spy: <Sinotify::PrimEvent :name => 'hi', :etypes => [:modify], :mask => 2 ...
|
98
|
+
... INFO -- : Sinotify::Notifier Event Spy <Sinotify::Event :path => '/tmp/sinotify_test/hi', dir? => false, :etypes => ...
|
99
|
+
... INFO -- : Sinotify::Notifier Prim Event Spy: <Sinotify::PrimEvent :name => 'hi', :etypes => [:delete], :mask => 200 ...
|
100
|
+
... INFO -- : Sinotify::Notifier Event Spy <Sinotify::Event :path => '/tmp/sinotify_test/hi', dir? => false, :etypes => ...
|
101
|
+
... INFO -- : Sinotify::Notifier Prim Event Spy: <Sinotify::PrimEvent :name => '', :etypes => [:delete_self], :mask => 400 ...
|
102
|
+
... INFO -- : Sinotify::Notifier Event Spy <Sinotify::Event :path => '/tmp/sinotify_test', dir? => true, :etypes => [:delete]...
|
103
|
+
etc.
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
== REQUIREMENTS:
|
108
|
+
|
109
|
+
* linux inotify dev libs
|
110
|
+
* cosell announcements framework gem
|
111
|
+
|
112
|
+
== INSTALL:
|
113
|
+
|
114
|
+
* Todo: install instruction
|
115
|
+
* sudo gem install cosell...
|
116
|
+
* sudo gem install sinotify...
|
117
|
+
|
118
|
+
== LICENSE:
|
119
|
+
|
120
|
+
(The MIT License)
|
121
|
+
|
122
|
+
Copyright (c) 2008 FIXME (different license?)
|
123
|
+
|
124
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
125
|
+
a copy of this software and associated documentation files (the
|
126
|
+
'Software'), to deal in the Software without restriction, including
|
127
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
128
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
129
|
+
permit persons to whom the Software is furnished to do so, subject to
|
130
|
+
the following conditions:
|
131
|
+
|
132
|
+
The above copyright notice and this permission notice shall be
|
133
|
+
included in all copies or substantial portions of the Software.
|
134
|
+
|
135
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
136
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
137
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
138
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
139
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
140
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
141
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.txt
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
sinotify
|
2
|
+
|
3
|
+
by {Steven Swerling}[http://tab-a.slot-z.net]
|
4
|
+
|
5
|
+
{rdoc}[http://tab-a.slot-z.net] | {github}[http://www.github.com/swerling/sinotify]
|
6
|
+
|
7
|
+
== DESCRIPTION:
|
8
|
+
|
9
|
+
ALPHA Alert -- just uploaded initial release.
|
10
|
+
|
11
|
+
|
12
|
+
Linux inotify is a means to receive events describing file system activity (create, modify, delete, close, etc).
|
13
|
+
|
14
|
+
Sinotify was derived from aredridel's package (http://raa.ruby-lang.org/project/ruby-inotify/), with the addition of
|
15
|
+
Paul Boon's tweak for making the event_check thread more polite (see
|
16
|
+
http://www.mindbucket.com/2009/02/24/ruby-daemons-verifying-good-behavior/)
|
17
|
+
|
18
|
+
In sinotify, the classes Sinotify::PrimNotifier and Sinotify::PrimEvent provide a low level wrapper to inotify, with
|
19
|
+
the ability to establish 'watches' and then listen for inotify events using one of inotify's synchronous event loops,
|
20
|
+
and providing access to the events' masks (see 'man inotify' for details). Sinotify::PrimEvent class adds a little semantic sugar
|
21
|
+
to the event in to the form of 'etypes', which are just ruby symbols that describe the event mask. If the event has a
|
22
|
+
raw mask of (DELETE_SELF & IS_DIR), then the etypes array would be [:delete_self, :is_dir].
|
23
|
+
|
24
|
+
In addition to the 'straight' wrapper in inotify, sinotify provides an asynchronous implementation of the 'observer
|
25
|
+
pattern' for notification. In other words, Sinotify::Notifier listens in the background for inotify events, adapting
|
26
|
+
them into instances of Sinotify::Event as they come in and immediately placing them in a concurrent queue, from which
|
27
|
+
they are 'announced' to 'subscribers' of the event. [Sinotify uses the 'cosell' implementation of the Announcements
|
28
|
+
event notification framework, hence the terminology 'subscribe' and 'announce' rather then 'listen' and 'trigger' used
|
29
|
+
in the standard event observer pattern. See the 'cosell' package on github for details.]
|
30
|
+
|
31
|
+
A variety of 'knobs' are provided for controlling the behavior of the notifier: whether a watch should apply to a
|
32
|
+
single directory or should recurse into subdirectores, how fast it should broadcast queued events, etc (see
|
33
|
+
Sinotify::Notifier, and the example in the synopsis section below). An event 'spy' can also be setup to log all
|
34
|
+
Sinotify::PrimEvents and Sinotify::Events.
|
35
|
+
|
36
|
+
Sinotify::Event simplifies inotify's muddled event model, sending events only for those files/directories that have
|
37
|
+
changed. That's not to say you can't setup a notifier that recurses into subdirectories, just that any individual
|
38
|
+
event will apply to a single file, and not to its children. Also, event types are identified using words (in the form
|
39
|
+
of ruby :symbols) instead of inotify's event masks. See Sinotify::Event for more explanation.
|
40
|
+
|
41
|
+
The README for inotify:
|
42
|
+
|
43
|
+
http://www.kernel.org/pub/linux/kernel/people/rml/inotify/README
|
44
|
+
|
45
|
+
Selected quotes from the README for inotify:
|
46
|
+
|
47
|
+
* "Rumor is that the 'd' in 'dnotify' does not stand for 'directory' but for 'suck.'"
|
48
|
+
|
49
|
+
* "The 'i' in inotify does not stand for 'suck' but for 'inode' -- the logical
|
50
|
+
choice since inotify is inode-based."
|
51
|
+
|
52
|
+
(The 's' in 'sinotify' does in fact stand for 'suck.')
|
53
|
+
|
54
|
+
|
55
|
+
== FEATURES/PROBLEMS:
|
56
|
+
|
57
|
+
* None known. But it's still early.
|
58
|
+
|
59
|
+
== SYNOPSIS:
|
60
|
+
|
61
|
+
Try this:
|
62
|
+
|
63
|
+
$ mkdir /tmp/sinotify_test
|
64
|
+
$ irb
|
65
|
+
require 'sinotify'
|
66
|
+
notifier = Sinotify::Notifier.new('/tmp/sinotify_test', :recurse => true, :etypes => [:create, :modify, :delete])
|
67
|
+
notifier.spy!(:logger => Logger.new('/tmp/inotify_spy.log')) # optional event spy
|
68
|
+
notifier.on_event do |sinotify_event|
|
69
|
+
puts "Event happened at #{sinotify_event.timestamp} on #{sinotify_event.path}, etypes => #{sinotify_event.etypes.inspect}"
|
70
|
+
end
|
71
|
+
notifier.on_event do |sinotify_event|
|
72
|
+
puts " --> demonstrate that multiple subscribers can be setup: #{sinotify_event.etypes.inspect}"
|
73
|
+
end
|
74
|
+
notifier.watch! # don't forget to start the watch
|
75
|
+
|
76
|
+
Then in another linux console:
|
77
|
+
|
78
|
+
$ touch /tmp/sinotify_test/hi && sleep 1 && echo 'hello' >> /tmp/sinotify_test/hi && sleep 1 && rm -r /tmp/sinotify_test
|
79
|
+
|
80
|
+
Back in irb you will see:
|
81
|
+
|
82
|
+
Event happened at Sat Jul 11 12:29:18 -0400 2009 on /tmp/sinotify_test/hi, etypes => [:create]
|
83
|
+
--> demonstrate that multiple subscribers can be setup: [:create]
|
84
|
+
Event happened at Sat Jul 11 12:29:19 -0400 2009 on /tmp/sinotify_test/hi, etypes => [:modify]
|
85
|
+
--> demonstrate that multiple subscribers can be setup: [:modify]
|
86
|
+
Event happened at Sat Jul 11 12:29:20 -0400 2009 on /tmp/sinotify_test/hi, etypes => [:delete]
|
87
|
+
--> demonstrate that multiple subscribers can be setup: [:delete]
|
88
|
+
Event happened at Sat Jul 11 12:29:20 -0400 2009 on /tmp/sinotify_test, etypes => [:delete]
|
89
|
+
--> demonstrate that multiple subscribers can be setup: [:delete]
|
90
|
+
|
91
|
+
|
92
|
+
tail -n 50 -f /tmp/inotify_spy.log:
|
93
|
+
|
94
|
+
...
|
95
|
+
... INFO -- : Sinotify::Notifier Prim Event Spy: <Sinotify::PrimEvent :name => 'hi', :etypes => [:create], :mask => 100 ...
|
96
|
+
... INFO -- : Sinotify::Notifier Event Spy <Sinotify::Event :path => '/tmp/sinotify_test/hi', dir? => false, :etypes => ...
|
97
|
+
... INFO -- : Sinotify::Notifier Prim Event Spy: <Sinotify::PrimEvent :name => 'hi', :etypes => [:modify], :mask => 2 ...
|
98
|
+
... INFO -- : Sinotify::Notifier Event Spy <Sinotify::Event :path => '/tmp/sinotify_test/hi', dir? => false, :etypes => ...
|
99
|
+
... INFO -- : Sinotify::Notifier Prim Event Spy: <Sinotify::PrimEvent :name => 'hi', :etypes => [:delete], :mask => 200 ...
|
100
|
+
... INFO -- : Sinotify::Notifier Event Spy <Sinotify::Event :path => '/tmp/sinotify_test/hi', dir? => false, :etypes => ...
|
101
|
+
... INFO -- : Sinotify::Notifier Prim Event Spy: <Sinotify::PrimEvent :name => '', :etypes => [:delete_self], :mask => 400 ...
|
102
|
+
... INFO -- : Sinotify::Notifier Event Spy <Sinotify::Event :path => '/tmp/sinotify_test', dir? => true, :etypes => [:delete]...
|
103
|
+
etc.
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
== REQUIREMENTS:
|
108
|
+
|
109
|
+
* linux inotify dev libs
|
110
|
+
* cosell announcements framework gem
|
111
|
+
|
112
|
+
== INSTALL:
|
113
|
+
|
114
|
+
* Todo: install instruction
|
115
|
+
* sudo gem install cosell...
|
116
|
+
* sudo gem install sinotify...
|
117
|
+
|
118
|
+
== LICENSE:
|
119
|
+
|
120
|
+
(The MIT License)
|
121
|
+
|
122
|
+
Copyright (c) 2008 FIXME (different license?)
|
123
|
+
|
124
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
125
|
+
a copy of this software and associated documentation files (the
|
126
|
+
'Software'), to deal in the Software without restriction, including
|
127
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
128
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
129
|
+
permit persons to whom the Software is furnished to do so, subject to
|
130
|
+
the following conditions:
|
131
|
+
|
132
|
+
The above copyright notice and this permission notice shall be
|
133
|
+
included in all copies or substantial portions of the Software.
|
134
|
+
|
135
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
136
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
137
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
138
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
139
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
140
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
141
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# Look in the tasks/setup.rb file for the various options that can be
|
2
|
+
# configured in this Rakefile. The .rake files in the tasks directory
|
3
|
+
# are where the options are used.
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'bones'
|
7
|
+
Bones.setup
|
8
|
+
rescue LoadError
|
9
|
+
begin
|
10
|
+
load 'tasks/setup.rb'
|
11
|
+
rescue LoadError
|
12
|
+
raise RuntimeError, '### please install the "bones" gem ###'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
#ensure_in_path 'lib'
|
17
|
+
|
18
|
+
require File.join(File.dirname(__FILE__), 'lib/sinotify_info')
|
19
|
+
|
20
|
+
# bones gem settings
|
21
|
+
PROJ.name = 'sinotify'
|
22
|
+
PROJ.authors = 'Steven Swerling'
|
23
|
+
PROJ.email = 'sswerling@yahoo.com'
|
24
|
+
PROJ.url = 'http://tab-a.slot-z.net'
|
25
|
+
PROJ.version = Sinotify::VERSION
|
26
|
+
PROJ.rubyforge.name = 'sinotify'
|
27
|
+
PROJ.gem.extentions = FileList['ext/**/extconf.rb']
|
28
|
+
PROJ.gem.dependencies = ['cosell']
|
29
|
+
PROJ.spec.opts << '--color'
|
30
|
+
PROJ.rdoc.opts = ["--inline-source"]
|
31
|
+
PROJ.rdoc.exclude = ["^tasks/setup\.rb$", "\.[ch]$"]
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
require 'fileutils'
|
38
|
+
def this_dir; File.join(File.dirname(__FILE__)); end
|
39
|
+
def doc_dir; File.join(this_dir, 'rdoc'); end
|
40
|
+
def ext_dir; File.join(this_dir, 'ext'); end
|
41
|
+
def tab_a_doc_dir; File.join(this_dir, '../tab-a/public/sinotify/rdoc'); end
|
42
|
+
|
43
|
+
task :default => 'spec:run'
|
44
|
+
task :myclobber => [:clobber] do
|
45
|
+
mydir = File.join(File.dirname(__FILE__))
|
46
|
+
sh "rm -rf #{File.join(mydir, 'pkg')}"
|
47
|
+
sh "rm -rf #{File.join(mydir, 'doc')}"
|
48
|
+
sh "rm -rf #{File.join(mydir, 'rdoc')}"
|
49
|
+
sh "rm -rf #{File.join(mydir, 'ext/*.log')}"
|
50
|
+
sh "rm -rf #{File.join(mydir, 'ext/*.o')}"
|
51
|
+
sh "rm -rf #{File.join(mydir, 'ext/*.so')}"
|
52
|
+
sh "rm -rf #{File.join(mydir, 'ext/Makefile')}"
|
53
|
+
sh "rm -rf #{File.join(mydir, 'ext/Makefile')}"
|
54
|
+
end
|
55
|
+
task :mypackage => [:myclobber] do
|
56
|
+
Rake::Task['gem:package'].invoke
|
57
|
+
end
|
58
|
+
task :mydoc => [:myclobber] do
|
59
|
+
FileUtils.rm_f doc_dir()
|
60
|
+
sh "cd #{this_dir()} && rdoc -o rdoc --inline-source --format=html -T hanna README.rdoc lib/**/*.rb"
|
61
|
+
end
|
62
|
+
task :taba => [:mydoc] do
|
63
|
+
this_dir = File.join(File.dirname(__FILE__))
|
64
|
+
FileUtils.rm_rf tab_a_doc_dir
|
65
|
+
FileUtils.cp_r doc_dir, tab_a_doc_dir
|
66
|
+
end
|
67
|
+
task :mygemspec => [:myclobber] do
|
68
|
+
Rake::Task['gem:spec'].invoke
|
69
|
+
end
|
70
|
+
task :mybuild => [:myclobber] do
|
71
|
+
sh "cd #{ext_dir} && ruby extconf.rb && make"
|
72
|
+
end
|
data/TODO
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
1. Refactor Notifier and Event so that other operating systems can be used for prim events.
|
2
|
+
|
3
|
+
Currently there are couplings between Event and PrimEvent that assume linux (easy to remove),
|
4
|
+
and couplings between Notifier and PrimEvent that assume linux (harder to remove, will need
|
5
|
+
an adapter class)
|
6
|
+
|
7
|
+
2. Batch collate events
|
8
|
+
|
9
|
+
Currently if you remove or add a directory with lots of files, events are sent out for
|
10
|
+
every single file. Would be nice option if a single event listing all the changes went
|
11
|
+
out (say, a single event that sponges up all events for 150 milliseconds, then sends them
|
12
|
+
off as an array)
|
data/examples/watcher.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
#!usr/bin/ruby
|
2
|
+
|
3
|
+
require 'sinotify'
|
4
|
+
require 'find'
|
5
|
+
|
6
|
+
i = Inotify.new
|
7
|
+
|
8
|
+
t = Thread.new do
|
9
|
+
i.each_event do |ev|
|
10
|
+
p ev.name
|
11
|
+
p ev.mask
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
raise("Specify a directory") if !ARGV[0]
|
16
|
+
|
17
|
+
Find.find(ARGV[0]) do |e|
|
18
|
+
if ['.svn', 'CVS', 'RCS'].include? File.basename(e) or !File.directory? e
|
19
|
+
Find.prune
|
20
|
+
else
|
21
|
+
begin
|
22
|
+
puts "Adding #{e}"
|
23
|
+
i.add_watch(e, Inotify::CREATE | Inotify::DELETE | Inotify::MOVE | Inotify::MODIFY)
|
24
|
+
rescue
|
25
|
+
puts "Skipping #{e}: #{$!}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
t.join
|
data/ext/extconf.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'mkmf'
|
2
|
+
|
3
|
+
dir = File.join(File.dirname(__FILE__))
|
4
|
+
|
5
|
+
if RUBY_VERSION =~ /1.9/ then
|
6
|
+
$CPPFLAGS += " -DRUBY_19"
|
7
|
+
end
|
8
|
+
|
9
|
+
have_header('linux/inotify.h')
|
10
|
+
# this was in the original inotify, but I don't know what it is for:
|
11
|
+
# have_header("version.h")
|
12
|
+
create_makefile('sinotify', 'src')
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#ifndef _LINUX_INOTIFY_SYSCALLS_H
|
2
|
+
#define _LINUX_INOTIFY_SYSCALLS_H
|
3
|
+
|
4
|
+
#if defined(__i386__)
|
5
|
+
# define __NR_inotify_init 291
|
6
|
+
# define __NR_inotify_add_watch 292
|
7
|
+
# define __NR_inotify_rm_watch 293
|
8
|
+
#elif defined(__x86_64__)
|
9
|
+
# define __NR_inotify_init 253
|
10
|
+
# define __NR_inotify_add_watch 254
|
11
|
+
# define __NR_inotify_rm_watch 255
|
12
|
+
#elif defined(__ppc__)
|
13
|
+
# define __NR_inotify_init 275
|
14
|
+
# define __NR_inotify_add_watch 276
|
15
|
+
# define __NR_inotify_rm_watch 277
|
16
|
+
#elif defined (__ia64__)
|
17
|
+
# define __NR_inotify_init 1277
|
18
|
+
# define __NR_inotify_add_watch 1278
|
19
|
+
# define __NR_inotify_rm_watch 1279
|
20
|
+
#else
|
21
|
+
# error "Unsupported architecture!"
|
22
|
+
#endif
|
23
|
+
|
24
|
+
#endif /* _LINUX_INOTIFY_SYSCALLS_H */
|