rb-inotify 0.10.0 → 0.11.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yaml +53 -0
- data/Gemfile +11 -7
- data/LICENSE.md +3 -3
- data/README.md +12 -4
- data/lib/rb-inotify/notifier.rb +21 -14
- data/lib/rb-inotify/version.rb +1 -1
- data/rb-inotify.gemspec +1 -6
- data/spec/notifier_spec.rb +24 -4
- metadata +9 -67
- data/.travis.yml +0 -21
- data/Rakefile +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0606a3b14ba7783689483410651837223b0a9d2967572cd768c421db22462bb
|
4
|
+
data.tar.gz: 28425a8d1c6c7067f365499185ef9916c0c9892fa467f74f5adbfc18039e4b19
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8b727242e12cb3debd140ac9b3e45a114f77c0642f33faa252f258360113ccf1fa16fb4c08ed1c16772884aef22d913ce394d3a4bf2be8a0754865a09e39f13
|
7
|
+
data.tar.gz: '02940752a3b3c8b44a465b71300290d60b910def4a56dfac8949a8f69379b8b58b01d278e58cb99c138eb8a6187fb8f44307efae15c9a3bf7c265991f90aebb4'
|
@@ -0,0 +1,53 @@
|
|
1
|
+
name: Test
|
2
|
+
|
3
|
+
on: [push, pull_request]
|
4
|
+
|
5
|
+
permissions:
|
6
|
+
contents: read
|
7
|
+
|
8
|
+
env:
|
9
|
+
CONSOLE_OUTPUT: XTerm
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
test:
|
13
|
+
name: ${{matrix.ruby}} on ${{matrix.os}}
|
14
|
+
runs-on: ${{matrix.os}}-latest
|
15
|
+
continue-on-error: ${{matrix.experimental}}
|
16
|
+
|
17
|
+
strategy:
|
18
|
+
matrix:
|
19
|
+
os:
|
20
|
+
- ubuntu
|
21
|
+
|
22
|
+
ruby:
|
23
|
+
- "2.5"
|
24
|
+
- "2.6"
|
25
|
+
- "2.7"
|
26
|
+
- "3.0"
|
27
|
+
- "3.1"
|
28
|
+
- "3.2"
|
29
|
+
- "3.3"
|
30
|
+
|
31
|
+
experimental: [false]
|
32
|
+
|
33
|
+
include:
|
34
|
+
- os: ubuntu
|
35
|
+
ruby: truffleruby
|
36
|
+
experimental: true
|
37
|
+
- os: ubuntu
|
38
|
+
ruby: jruby
|
39
|
+
experimental: true
|
40
|
+
- os: ubuntu
|
41
|
+
ruby: head
|
42
|
+
experimental: true
|
43
|
+
|
44
|
+
steps:
|
45
|
+
- uses: actions/checkout@v4
|
46
|
+
- uses: ruby/setup-ruby@v1
|
47
|
+
with:
|
48
|
+
ruby-version: ${{matrix.ruby}}
|
49
|
+
bundler-cache: true
|
50
|
+
|
51
|
+
- name: Run tests
|
52
|
+
timeout-minutes: 10
|
53
|
+
run: bundle exec rspec
|
data/Gemfile
CHANGED
@@ -3,14 +3,18 @@ source 'https://rubygems.org'
|
|
3
3
|
# Specify your gem's dependencies in utopia.gemspec
|
4
4
|
gemspec
|
5
5
|
|
6
|
-
group :
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
gem 'tty-prompt'
|
6
|
+
group :maintenance, optional: true do
|
7
|
+
gem "bake-gem"
|
8
|
+
gem "bake-modernize"
|
11
9
|
end
|
12
10
|
|
13
11
|
group :test do
|
14
|
-
|
15
|
-
|
12
|
+
gem "rspec", "~> 3.6"
|
13
|
+
|
14
|
+
gem 'simplecov'
|
15
|
+
gem 'coveralls', require: false
|
16
|
+
|
17
|
+
gem "bundler"
|
18
|
+
gem "rake"
|
19
|
+
gem "concurrent-ruby"
|
16
20
|
end
|
data/LICENSE.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
# The MIT License
|
1
|
+
# The MIT License
|
2
2
|
|
3
|
-
Copyright, 2009, by [Natalie Weizenbaum](https://github.com/nex3).
|
4
|
-
Copyright, 2017, by [Samuel G. D. Williams](http://www.codeotaku.com
|
3
|
+
Copyright, 2009, by [Natalie Weizenbaum](https://github.com/nex3).
|
4
|
+
Copyright, 2017, by [Samuel G. D. Williams](http://www.codeotaku.com).
|
5
5
|
|
6
6
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
7
7
|
|
data/README.md
CHANGED
@@ -6,11 +6,9 @@ It uses the [FFI](http://wiki.github.com/ffi/ffi) gem to avoid having to compile
|
|
6
6
|
|
7
7
|
[API documentation is available on rdoc.info](http://rdoc.info/projects/nex3/rb-inotify).
|
8
8
|
|
9
|
-
[![
|
10
|
-
[![Code Climate](https://codeclimate.com/github/guard/rb-inotify.svg)](https://codeclimate.com/github/guard/rb-inotify)
|
11
|
-
[![Coverage Status](https://coveralls.io/repos/guard/rb-inotify/badge.svg)](https://coveralls.io/r/guard/rb-inotify)
|
9
|
+
[![Development Status](https://github.com/guard/rb-inotify/workflows/Test/badge.svg)](https://github.com/guard/rb-inotify/actions?workflow=Test)
|
12
10
|
|
13
|
-
##
|
11
|
+
## Usage
|
14
12
|
|
15
13
|
The API is similar to the inotify C API, but with a more Rubyish feel.
|
16
14
|
First, create a notifier:
|
@@ -69,6 +67,16 @@ Unfortunately, this currently doesn't work under JRuby.
|
|
69
67
|
JRuby currently doesn't use native file descriptors for the IO object,
|
70
68
|
so we can't use the notifier's file descriptor as a stand-in.
|
71
69
|
|
70
|
+
### Resource Limits
|
71
|
+
|
72
|
+
If you get an error like `inotify event queue has overflowed` you might be running into system limits. You can add the following to your `/etc/sysctl.conf` to increase the number of files that can be monitored:
|
73
|
+
|
74
|
+
```
|
75
|
+
fs.inotify.max_user_watches = 100000
|
76
|
+
fs.inotify.max_queued_events = 100000
|
77
|
+
fs.inotify.max_user_instances = 100000
|
78
|
+
```
|
79
|
+
|
72
80
|
## Contributing
|
73
81
|
|
74
82
|
1. Fork it
|
data/lib/rb-inotify/notifier.rb
CHANGED
@@ -24,10 +24,8 @@ module INotify
|
|
24
24
|
# # Nothing happens until you run the notifier!
|
25
25
|
# notifier.run
|
26
26
|
class Notifier
|
27
|
-
# A list of directories that should never be recursively watched.
|
28
|
-
#
|
29
27
|
# * Files in `/dev/fd` sometimes register as directories, but are not enumerable.
|
30
|
-
|
28
|
+
NON_RECURSIVE = "/dev/fd"
|
31
29
|
|
32
30
|
# A hash from {Watcher} ids to the instances themselves.
|
33
31
|
#
|
@@ -50,13 +48,20 @@ module INotify
|
|
50
48
|
# @raise [SystemCallError] if inotify failed to initialize for some reason
|
51
49
|
def initialize
|
52
50
|
@running = Mutex.new
|
51
|
+
@stop = false
|
53
52
|
@pipe = IO.pipe
|
53
|
+
# JRuby shutdown sometimes runs IO finalizers before all threads finish.
|
54
|
+
if RUBY_ENGINE == 'jruby'
|
55
|
+
@pipe[0].autoclose = false
|
56
|
+
@pipe[1].autoclose = false
|
57
|
+
end
|
54
58
|
|
55
59
|
@watchers = {}
|
56
60
|
|
57
61
|
fd = Native.inotify_init
|
58
62
|
unless fd < 0
|
59
63
|
@handle = IO.new(fd)
|
64
|
+
@handle.autoclose = false if RUBY_ENGINE == 'jruby'
|
60
65
|
return
|
61
66
|
end
|
62
67
|
|
@@ -191,20 +196,17 @@ module INotify
|
|
191
196
|
def watch(path, *flags, &callback)
|
192
197
|
return Watcher.new(self, path, *flags, &callback) unless flags.include?(:recursive)
|
193
198
|
|
194
|
-
|
199
|
+
dont_follow = flags.include?(:dont_follow)
|
195
200
|
|
196
|
-
|
201
|
+
Dir.each_child(path) do |base|
|
197
202
|
d = File.join(path, base)
|
198
|
-
|
199
|
-
next if
|
200
|
-
next if
|
201
|
-
next if flags.include?(:dont_follow) && File.symlink?(d)
|
202
|
-
next if !File.directory?(d)
|
203
|
+
next unless File.directory?(d)
|
204
|
+
next if dont_follow && File.symlink?(d)
|
205
|
+
next if NON_RECURSIVE == d
|
203
206
|
|
204
207
|
watch(d, *flags, &callback)
|
205
208
|
end
|
206
209
|
|
207
|
-
dir.close
|
208
210
|
|
209
211
|
rec_flags = [:create, :moved_to]
|
210
212
|
return watch(path, *((flags - [:recursive]) | rec_flags)) do |event|
|
@@ -224,10 +226,13 @@ module INotify
|
|
224
226
|
# @see #process
|
225
227
|
def run
|
226
228
|
@running.synchronize do
|
227
|
-
|
229
|
+
Thread.current[:INOTIFY_RUN_THREAD] = true
|
228
230
|
|
229
231
|
process until @stop
|
230
232
|
end
|
233
|
+
ensure
|
234
|
+
Thread.current[:INOTIFY_RUN_THREAD] = false
|
235
|
+
@stop = false
|
231
236
|
end
|
232
237
|
|
233
238
|
# Stop watching for filesystem events.
|
@@ -237,8 +242,10 @@ module INotify
|
|
237
242
|
@stop = true
|
238
243
|
@pipe.last.write "."
|
239
244
|
|
240
|
-
|
241
|
-
|
245
|
+
unless Thread.current[:INOTIFY_RUN_THREAD]
|
246
|
+
@running.synchronize do
|
247
|
+
# no-op: we just needed to wait until the lock was available
|
248
|
+
end
|
242
249
|
end
|
243
250
|
end
|
244
251
|
|
data/lib/rb-inotify/version.rb
CHANGED
data/rb-inotify.gemspec
CHANGED
@@ -17,12 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
|
-
spec.required_ruby_version = '>= 2.
|
20
|
+
spec.required_ruby_version = '>= 2.5'
|
21
21
|
|
22
22
|
spec.add_dependency "ffi", "~> 1.0"
|
23
|
-
|
24
|
-
spec.add_development_dependency "rspec", "~> 3.6"
|
25
|
-
spec.add_development_dependency "bundler"
|
26
|
-
spec.add_development_dependency "rake"
|
27
|
-
spec.add_development_dependency "concurrent-ruby"
|
28
23
|
end
|
data/spec/notifier_spec.rb
CHANGED
@@ -94,13 +94,33 @@ describe INotify::Notifier do
|
|
94
94
|
@notifier.stop
|
95
95
|
|
96
96
|
dir.join("three.txt").write("hello world")
|
97
|
-
|
98
|
-
|
99
|
-
dir.join("four.txt").write("hello world")
|
100
|
-
run_thread.join
|
97
|
+
run_thread.join(1) or raise "timeout"
|
101
98
|
|
102
99
|
expect(events.map(&:name)).to match_array(%w(one.txt two.txt))
|
103
100
|
end
|
101
|
+
|
102
|
+
it "can be stopped from within a callback" do
|
103
|
+
recording(dir, :create) { @notifier.stop }
|
104
|
+
|
105
|
+
run_thread = Thread.new { @notifier.run }
|
106
|
+
|
107
|
+
dir.join("one.txt").write("hello world")
|
108
|
+
run_thread.join(1) or raise "timeout"
|
109
|
+
end
|
110
|
+
|
111
|
+
it "can be stopped before it starts processing" do
|
112
|
+
barrier = Concurrent::Event.new
|
113
|
+
|
114
|
+
run_thread = Thread.new do
|
115
|
+
barrier.wait
|
116
|
+
@notifier.run
|
117
|
+
end
|
118
|
+
|
119
|
+
@notifier.stop
|
120
|
+
barrier.set
|
121
|
+
|
122
|
+
run_thread.join(1) or raise "timeout"
|
123
|
+
end
|
104
124
|
end
|
105
125
|
|
106
126
|
describe :fd do
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rb-inotify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Natalie Weizenbaum
|
8
8
|
- Samuel Williams
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2024-05-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ffi
|
@@ -25,63 +25,7 @@ dependencies:
|
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '1.0'
|
28
|
-
|
29
|
-
name: rspec
|
30
|
-
requirement: !ruby/object:Gem::Requirement
|
31
|
-
requirements:
|
32
|
-
- - "~>"
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version: '3.6'
|
35
|
-
type: :development
|
36
|
-
prerelease: false
|
37
|
-
version_requirements: !ruby/object:Gem::Requirement
|
38
|
-
requirements:
|
39
|
-
- - "~>"
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
version: '3.6'
|
42
|
-
- !ruby/object:Gem::Dependency
|
43
|
-
name: bundler
|
44
|
-
requirement: !ruby/object:Gem::Requirement
|
45
|
-
requirements:
|
46
|
-
- - ">="
|
47
|
-
- !ruby/object:Gem::Version
|
48
|
-
version: '0'
|
49
|
-
type: :development
|
50
|
-
prerelease: false
|
51
|
-
version_requirements: !ruby/object:Gem::Requirement
|
52
|
-
requirements:
|
53
|
-
- - ">="
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
version: '0'
|
56
|
-
- !ruby/object:Gem::Dependency
|
57
|
-
name: rake
|
58
|
-
requirement: !ruby/object:Gem::Requirement
|
59
|
-
requirements:
|
60
|
-
- - ">="
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version: '0'
|
63
|
-
type: :development
|
64
|
-
prerelease: false
|
65
|
-
version_requirements: !ruby/object:Gem::Requirement
|
66
|
-
requirements:
|
67
|
-
- - ">="
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: '0'
|
70
|
-
- !ruby/object:Gem::Dependency
|
71
|
-
name: concurrent-ruby
|
72
|
-
requirement: !ruby/object:Gem::Requirement
|
73
|
-
requirements:
|
74
|
-
- - ">="
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
version: '0'
|
77
|
-
type: :development
|
78
|
-
prerelease: false
|
79
|
-
version_requirements: !ruby/object:Gem::Requirement
|
80
|
-
requirements:
|
81
|
-
- - ">="
|
82
|
-
- !ruby/object:Gem::Version
|
83
|
-
version: '0'
|
84
|
-
description:
|
28
|
+
description:
|
85
29
|
email:
|
86
30
|
- nex342@gmail.com
|
87
31
|
- samuel.williams@oriontransfer.co.nz
|
@@ -89,13 +33,12 @@ executables: []
|
|
89
33
|
extensions: []
|
90
34
|
extra_rdoc_files: []
|
91
35
|
files:
|
36
|
+
- ".github/workflows/test.yaml"
|
92
37
|
- ".gitignore"
|
93
|
-
- ".travis.yml"
|
94
38
|
- ".yardopts"
|
95
39
|
- Gemfile
|
96
40
|
- LICENSE.md
|
97
41
|
- README.md
|
98
|
-
- Rakefile
|
99
42
|
- lib/rb-inotify.rb
|
100
43
|
- lib/rb-inotify/errors.rb
|
101
44
|
- lib/rb-inotify/event.rb
|
@@ -112,7 +55,7 @@ homepage: https://github.com/guard/rb-inotify
|
|
112
55
|
licenses:
|
113
56
|
- MIT
|
114
57
|
metadata: {}
|
115
|
-
post_install_message:
|
58
|
+
post_install_message:
|
116
59
|
rdoc_options: []
|
117
60
|
require_paths:
|
118
61
|
- lib
|
@@ -120,16 +63,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
120
63
|
requirements:
|
121
64
|
- - ">="
|
122
65
|
- !ruby/object:Gem::Version
|
123
|
-
version: '2.
|
66
|
+
version: '2.5'
|
124
67
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
68
|
requirements:
|
126
69
|
- - ">="
|
127
70
|
- !ruby/object:Gem::Version
|
128
71
|
version: '0'
|
129
72
|
requirements: []
|
130
|
-
|
131
|
-
|
132
|
-
signing_key:
|
73
|
+
rubygems_version: 3.5.3
|
74
|
+
signing_key:
|
133
75
|
specification_version: 4
|
134
76
|
summary: A Ruby wrapper for Linux inotify, using FFI
|
135
77
|
test_files:
|
data/.travis.yml
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
cache: bundler
|
3
|
-
|
4
|
-
matrix:
|
5
|
-
include:
|
6
|
-
- rvm: 2.3
|
7
|
-
- rvm: 2.4
|
8
|
-
- rvm: 2.5
|
9
|
-
- rvm: 2.6
|
10
|
-
- rvm: jruby
|
11
|
-
- rvm: truffleruby
|
12
|
-
- rvm: jruby-head
|
13
|
-
- rvm: ruby-head
|
14
|
-
- rvm: rbx-3
|
15
|
-
allow_failures:
|
16
|
-
- rvm: truffleruby
|
17
|
-
- rvm: jruby
|
18
|
-
- rvm: ruby-head
|
19
|
-
- rvm: jruby-head
|
20
|
-
- rvm: rbx-3
|
21
|
-
fast_finish: true
|