From b56424417fd85951ecb22e55a9b78ec2b5ac06a7 Mon Sep 17 00:00:00 2001 From: uvlad7 Date: Mon, 23 Jun 2025 14:56:10 +0300 Subject: [PATCH 01/14] Impl IN_EXCL_UNLINK and IN_MASK_CREATE, guard IN_ONLYDIR and IN_DONT_FOLLOW --- lib/rb-inotify/native/flags.rb | 23 +++++++++++++++++++---- lib/rb-inotify/notifier.rb | 10 ++++++++-- rb-inotify.gemspec | 1 + spec/notifier_spec.rb | 13 +++++++++++++ 4 files changed, 41 insertions(+), 6 deletions(-) diff --git a/lib/rb-inotify/native/flags.rb b/lib/rb-inotify/native/flags.rb index 5640130..42776d6 100644 --- a/lib/rb-inotify/native/flags.rb +++ b/lib/rb-inotify/native/flags.rb @@ -1,3 +1,5 @@ +require "etc" + module INotify module Native # A module containing all the inotify flags @@ -5,6 +7,7 @@ module Native # # @private module Flags + LINUX_KERNEL_VERSION = Gem::Version.new(Etc.uname[:release]) # File was accessed. IN_ACCESS = 0x00000001 # Metadata changed. @@ -44,10 +47,22 @@ module Flags ## Special flags. - # Only watch the path if it is a directory. - IN_ONLYDIR = 0x01000000 - # Do not follow a sym link. - IN_DONT_FOLLOW = 0x02000000 + if LINUX_KERNEL_VERSION >= "2.6.15" + # Only watch the path if it is a directory. + IN_ONLYDIR = 0x01000000 + # Do not follow a sym link. + IN_DONT_FOLLOW = 0x02000000 + end + + if LINUX_KERNEL_VERSION >= "2.6.36" + # Exclude events on unlinked objects. + IN_EXCL_UNLINK = 0x04000000 + end + if LINUX_KERNEL_VERSION >= "4.18" + # Only create watches. + IN_MASK_CREATE = 0x10000000 + end + # Add to the mask of an already existing watch. IN_MASK_ADD = 0x20000000 # Only send event once. diff --git a/lib/rb-inotify/notifier.rb b/lib/rb-inotify/notifier.rb index 398ef99..4a65ab4 100644 --- a/lib/rb-inotify/notifier.rb +++ b/lib/rb-inotify/notifier.rb @@ -164,10 +164,16 @@ def to_io # Instead, they specify options for the watcher. # # `:onlydir` - # : Only watch the path if it's a directory. + # : Only watch the path if it's a directory; since Linux 2.6.15 # # `:dont_follow` - # : Don't follow symlinks. + # : Don't follow symlinks; since Linux 2.6.15 + # + # `:excl_unlink` + # : Exclude events on unlinked objects; since Linux 2.6.36 + # + # `:mask_create` + # : Watch pathname only if it does not already have a watch associated with it, Errno::EEXIST is raised otherwise; since Linux 4.18 # # `:mask_add` # : Add these flags to the pre-existing flags for this path. diff --git a/rb-inotify.gemspec b/rb-inotify.gemspec index 5ce4bc3..bb48064 100644 --- a/rb-inotify.gemspec +++ b/rb-inotify.gemspec @@ -20,4 +20,5 @@ Gem::Specification.new do |spec| spec.required_ruby_version = '>= 2.5' spec.add_dependency "ffi", "~> 1.0" + spec.add_dependency "etc" end diff --git a/spec/notifier_spec.rb b/spec/notifier_spec.rb index 8370151..37cd5f2 100644 --- a/spec/notifier_spec.rb +++ b/spec/notifier_spec.rb @@ -41,6 +41,19 @@ expect(events.first.absolute_name).to eq(dir.join("test.txt").to_s) end + it "ensures that new watches do not modify existing ones" do + skip "too old kernel" unless defined?(INotify::Native::Flags::IN_MASK_CREATE) + + events = recording(dir, :create, :oneshot, :mask_create) + expect do + recording(dir, :create, :oneshot, :mask_create) + end.to raise_error(Errno::EEXIST) + dir.join("test.txt").write("hello world") + expect do + recording(dir, :create, :oneshot, :mask_create) + end.not_to raise_error + end + it "gets simultaneous events" do events = recording(dir, :create) From d6e2b2a2e12c7605dada611c9e634564e6500037 Mon Sep 17 00:00:00 2001 From: uvlad7 Date: Mon, 23 Jun 2025 16:46:31 +0300 Subject: [PATCH 02/14] fast debug github ci, sorry --- lib/rb-inotify/native/flags.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/rb-inotify/native/flags.rb b/lib/rb-inotify/native/flags.rb index 42776d6..e6fbf0d 100644 --- a/lib/rb-inotify/native/flags.rb +++ b/lib/rb-inotify/native/flags.rb @@ -8,6 +8,7 @@ module Native # @private module Flags LINUX_KERNEL_VERSION = Gem::Version.new(Etc.uname[:release]) + p LINUX_KERNEL_VERSION # File was accessed. IN_ACCESS = 0x00000001 # Metadata changed. From 16e41441f76dce67e02d884a6dbe2e8369270c75 Mon Sep 17 00:00:00 2001 From: uvlad7 Date: Mon, 23 Jun 2025 16:49:28 +0300 Subject: [PATCH 03/14] fast debug github ci, sorry --- lib/rb-inotify/native/flags.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rb-inotify/native/flags.rb b/lib/rb-inotify/native/flags.rb index e6fbf0d..1b2e253 100644 --- a/lib/rb-inotify/native/flags.rb +++ b/lib/rb-inotify/native/flags.rb @@ -8,7 +8,7 @@ module Native # @private module Flags LINUX_KERNEL_VERSION = Gem::Version.new(Etc.uname[:release]) - p LINUX_KERNEL_VERSION + p LINUX_KERNEL_VERSION # trigger workflow # File was accessed. IN_ACCESS = 0x00000001 # Metadata changed. From e766d9a7c67c44ca311af9853b468d485b323af3 Mon Sep 17 00:00:00 2001 From: uvlad7 Date: Mon, 23 Jun 2025 16:57:49 +0300 Subject: [PATCH 04/14] fast debug github ci, sorry --- lib/rb-inotify/native/flags.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/rb-inotify/native/flags.rb b/lib/rb-inotify/native/flags.rb index 1b2e253..31920ca 100644 --- a/lib/rb-inotify/native/flags.rb +++ b/lib/rb-inotify/native/flags.rb @@ -9,6 +9,11 @@ module Native module Flags LINUX_KERNEL_VERSION = Gem::Version.new(Etc.uname[:release]) p LINUX_KERNEL_VERSION # trigger workflow + begin + LINUX_KERNEL_VERSION >= "2.6.15" + rescue ArgumentError => e + p e.backtrace + end # File was accessed. IN_ACCESS = 0x00000001 # Metadata changed. From e442facbb5ff0cb7e1149d93917c95a462fc40eb Mon Sep 17 00:00:00 2001 From: uvlad7 Date: Mon, 23 Jun 2025 17:00:53 +0300 Subject: [PATCH 05/14] fast debug github ci, sorry --- lib/rb-inotify/native/flags.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/rb-inotify/native/flags.rb b/lib/rb-inotify/native/flags.rb index 31920ca..0d45330 100644 --- a/lib/rb-inotify/native/flags.rb +++ b/lib/rb-inotify/native/flags.rb @@ -9,6 +9,8 @@ module Native module Flags LINUX_KERNEL_VERSION = Gem::Version.new(Etc.uname[:release]) p LINUX_KERNEL_VERSION # trigger workflow + p Gem::Version.instance_method(:<=>) + p Gem::Version.instance_method(:=>) begin LINUX_KERNEL_VERSION >= "2.6.15" rescue ArgumentError => e From 03db9b4bd708a0193aa16200a8805ac7b7c908f5 Mon Sep 17 00:00:00 2001 From: uvlad7 Date: Mon, 23 Jun 2025 17:02:01 +0300 Subject: [PATCH 06/14] fast debug github ci, sorry --- lib/rb-inotify/native/flags.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rb-inotify/native/flags.rb b/lib/rb-inotify/native/flags.rb index 0d45330..15bafa9 100644 --- a/lib/rb-inotify/native/flags.rb +++ b/lib/rb-inotify/native/flags.rb @@ -10,7 +10,7 @@ module Flags LINUX_KERNEL_VERSION = Gem::Version.new(Etc.uname[:release]) p LINUX_KERNEL_VERSION # trigger workflow p Gem::Version.instance_method(:<=>) - p Gem::Version.instance_method(:=>) + p Gem::Version.instance_method(:>=) begin LINUX_KERNEL_VERSION >= "2.6.15" rescue ArgumentError => e From e4a519c6536091ee1992517d96c4912afcc97834 Mon Sep 17 00:00:00 2001 From: uvlad7 Date: Mon, 23 Jun 2025 17:21:45 +0300 Subject: [PATCH 07/14] fix Gem::Version --- lib/rb-inotify/native/flags.rb | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/lib/rb-inotify/native/flags.rb b/lib/rb-inotify/native/flags.rb index 15bafa9..1ddf645 100644 --- a/lib/rb-inotify/native/flags.rb +++ b/lib/rb-inotify/native/flags.rb @@ -8,14 +8,6 @@ module Native # @private module Flags LINUX_KERNEL_VERSION = Gem::Version.new(Etc.uname[:release]) - p LINUX_KERNEL_VERSION # trigger workflow - p Gem::Version.instance_method(:<=>) - p Gem::Version.instance_method(:>=) - begin - LINUX_KERNEL_VERSION >= "2.6.15" - rescue ArgumentError => e - p e.backtrace - end # File was accessed. IN_ACCESS = 0x00000001 # Metadata changed. @@ -55,18 +47,18 @@ module Flags ## Special flags. - if LINUX_KERNEL_VERSION >= "2.6.15" + if LINUX_KERNEL_VERSION >= Gem::Version.new("2.6.15") # Only watch the path if it is a directory. IN_ONLYDIR = 0x01000000 # Do not follow a sym link. IN_DONT_FOLLOW = 0x02000000 end - if LINUX_KERNEL_VERSION >= "2.6.36" + if LINUX_KERNEL_VERSION >= Gem::Version.new("2.6.36") # Exclude events on unlinked objects. IN_EXCL_UNLINK = 0x04000000 end - if LINUX_KERNEL_VERSION >= "4.18" + if LINUX_KERNEL_VERSION >= Gem::Version.new("4.18") # Only create watches. IN_MASK_CREATE = 0x10000000 end From 3ae1fd72434fde8d950085225d3f24386ef71362 Mon Sep 17 00:00:00 2001 From: uvlad7 Date: Mon, 23 Jun 2025 18:05:03 +0300 Subject: [PATCH 08/14] fix compat issues --- lib/rb-inotify/native/flags.rb | 7 ++++++- rb-inotify.gemspec | 5 ++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/rb-inotify/native/flags.rb b/lib/rb-inotify/native/flags.rb index 1ddf645..b170e89 100644 --- a/lib/rb-inotify/native/flags.rb +++ b/lib/rb-inotify/native/flags.rb @@ -7,7 +7,12 @@ module Native # # @private module Flags - LINUX_KERNEL_VERSION = Gem::Version.new(Etc.uname[:release]) + uname = Etc.uname + # JRuby always writes release: 'unknown', but :version contains what :release contains on MRI and TruffleRuby. + release = RUBY_PLATFORM == "java" ? uname[:version] : uname[:release] + # give up + release = '0.1.0' unless Gem::Version.correct?(release) + LINUX_KERNEL_VERSION = Gem::Version.new(release) # File was accessed. IN_ACCESS = 0x00000001 # Metadata changed. diff --git a/rb-inotify.gemspec b/rb-inotify.gemspec index bb48064..edd9fb9 100644 --- a/rb-inotify.gemspec +++ b/rb-inotify.gemspec @@ -20,5 +20,8 @@ Gem::Specification.new do |spec| spec.required_ruby_version = '>= 2.5' spec.add_dependency "ffi", "~> 1.0" - spec.add_dependency "etc" + # Isn't added as a dependency because + # - It's a default gem on MRI 3.4.2 and TruffleRuby 24.2.1 + # - It's not available as a gem on JRuby + # spec.add_dependency "etc" end From c7416be24c40243d7e4a6b2474f48fd5d342875f Mon Sep 17 00:00:00 2001 From: uvlad7 Date: Mon, 23 Jun 2025 18:11:00 +0300 Subject: [PATCH 09/14] spec to ensure unsupported flags cause an error --- spec/notifier_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spec/notifier_spec.rb b/spec/notifier_spec.rb index 37cd5f2..bc84b51 100644 --- a/spec/notifier_spec.rb +++ b/spec/notifier_spec.rb @@ -54,6 +54,12 @@ end.not_to raise_error end + it "fails if flags are not supported" do + expect do + recording(dir, :create, :oneshot, :unknown_flag) + end.to raise_error(NameError, 'uninitialized constant INotify::Native::Flags::IN_UNKNOWN_FLAG') + end + it "gets simultaneous events" do events = recording(dir, :create) From 66bd82ba9f153c8ff1bfd9b3190a0215076660d7 Mon Sep 17 00:00:00 2001 From: uvlad7 Date: Mon, 23 Jun 2025 18:18:56 +0300 Subject: [PATCH 10/14] unify jruby check --- lib/rb-inotify/native/flags.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rb-inotify/native/flags.rb b/lib/rb-inotify/native/flags.rb index b170e89..0cb8aba 100644 --- a/lib/rb-inotify/native/flags.rb +++ b/lib/rb-inotify/native/flags.rb @@ -9,7 +9,7 @@ module Native module Flags uname = Etc.uname # JRuby always writes release: 'unknown', but :version contains what :release contains on MRI and TruffleRuby. - release = RUBY_PLATFORM == "java" ? uname[:version] : uname[:release] + release = RUBY_ENGINE == 'jruby' ? uname[:version] : uname[:release] # give up release = '0.1.0' unless Gem::Version.correct?(release) LINUX_KERNEL_VERSION = Gem::Version.new(release) From 44d17cc0d3dd386e44ec509ce9f0e62f111a6e2c Mon Sep 17 00:00:00 2001 From: uvlad7 Date: Mon, 23 Jun 2025 19:38:34 +0300 Subject: [PATCH 11/14] validate add_watch flags, rearrange flags to match manpage --- lib/rb-inotify/native/flags.rb | 49 ++++++++++++++++++++++------------ spec/notifier_spec.rb | 3 +++ 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/lib/rb-inotify/native/flags.rb b/lib/rb-inotify/native/flags.rb index 0cb8aba..d5f2859 100644 --- a/lib/rb-inotify/native/flags.rb +++ b/lib/rb-inotify/native/flags.rb @@ -19,31 +19,31 @@ module Flags IN_ATTRIB = 0x00000004 # Writtable file was closed. IN_CLOSE_WRITE = 0x00000008 - # File was modified. - IN_MODIFY = 0x00000002 # Unwrittable file closed. IN_CLOSE_NOWRITE = 0x00000010 - # File was opened. - IN_OPEN = 0x00000020 - # File was moved from X. - IN_MOVED_FROM = 0x00000040 - # File was moved to Y. - IN_MOVED_TO = 0x00000080 # Subfile was created. IN_CREATE = 0x00000100 # Subfile was deleted. IN_DELETE = 0x00000200 # Self was deleted. IN_DELETE_SELF = 0x00000400 + # File was modified. + IN_MODIFY = 0x00000002 # Self was moved. IN_MOVE_SELF = 0x00000800 + # File was moved from X. + IN_MOVED_FROM = 0x00000040 + # File was moved to Y. + IN_MOVED_TO = 0x00000080 + # File was opened. + IN_OPEN = 0x00000020 ## Helper events. - # Close. - IN_CLOSE = (IN_CLOSE_WRITE | IN_CLOSE_NOWRITE) # Moves. IN_MOVE = (IN_MOVED_FROM | IN_MOVED_TO) + # Close. + IN_CLOSE = (IN_CLOSE_WRITE | IN_CLOSE_NOWRITE) # All events which a program can wait on. IN_ALL_EVENTS = (IN_ACCESS | IN_MODIFY | IN_ATTRIB | IN_CLOSE_WRITE | IN_CLOSE_NOWRITE | IN_OPEN | IN_MOVED_FROM | IN_MOVED_TO | IN_CREATE | @@ -53,10 +53,10 @@ module Flags ## Special flags. if LINUX_KERNEL_VERSION >= Gem::Version.new("2.6.15") - # Only watch the path if it is a directory. - IN_ONLYDIR = 0x01000000 # Do not follow a sym link. IN_DONT_FOLLOW = 0x02000000 + # Only watch the path if it is a directory. + IN_ONLYDIR = 0x01000000 end if LINUX_KERNEL_VERSION >= Gem::Version.new("2.6.36") @@ -76,14 +76,16 @@ module Flags ## Events sent by the kernel. - # Backing fs was unmounted. - IN_UNMOUNT = 0x00002000 - # Event queued overflowed. - IN_Q_OVERFLOW = 0x00004000 # File was ignored. IN_IGNORED = 0x00008000 # Event occurred against dir. IN_ISDIR = 0x40000000 + # Backing fs was unmounted. + IN_UNMOUNT = 0x00002000 + # Event queued overflowed. + IN_Q_OVERFLOW = 0x00004000 + + EVENT_ONLY_FLAGS = IN_IGNORED | IN_ISDIR | IN_UNMOUNT | IN_Q_OVERFLOW ## fpathconf Macros @@ -95,10 +97,23 @@ module Flags # @param flags [Array] # @return [Fixnum] def self.to_mask(flags) - flags.map {|flag| const_get("IN_#{flag.to_s.upcase}")}. + flags.map {|flag| to_add_watch_flag(flag) }. inject(0) {|mask, flag| mask | flag} end + # Converts a flag to the value that can be used in inotify_add_watch + # + # @param flag [Symbol] + # @return [Fixnum] + # @raise [NameError] if the flag is not supported + # @raise [ArgumentError] if the flag is defined, but can't be used in inotify_add_watch + def self.to_add_watch_flag(flag) + res = const_get("IN_#{flag.to_s.upcase}") + raise ArgumentError, "Invalid flag: #{flag}" if EVENT_ONLY_FLAGS & res != 0 + + res + end + # Converts a bitmask from the C API into a list of flags. # # @param mask [Fixnum] diff --git a/spec/notifier_spec.rb b/spec/notifier_spec.rb index bc84b51..5bec8c7 100644 --- a/spec/notifier_spec.rb +++ b/spec/notifier_spec.rb @@ -58,6 +58,9 @@ expect do recording(dir, :create, :oneshot, :unknown_flag) end.to raise_error(NameError, 'uninitialized constant INotify::Native::Flags::IN_UNKNOWN_FLAG') + expect do + recording(dir, :create, :isdir) + end.to raise_error(ArgumentError, 'Invalid flag: isdir') end it "gets simultaneous events" do From 062b9605a664a9c064d3f2df93a48a78e7da90ce Mon Sep 17 00:00:00 2001 From: uvlad7 Date: Mon, 23 Jun 2025 20:55:06 +0300 Subject: [PATCH 12/14] fix spec --- spec/notifier_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/notifier_spec.rb b/spec/notifier_spec.rb index 5bec8c7..ffeddad 100644 --- a/spec/notifier_spec.rb +++ b/spec/notifier_spec.rb @@ -44,7 +44,7 @@ it "ensures that new watches do not modify existing ones" do skip "too old kernel" unless defined?(INotify::Native::Flags::IN_MASK_CREATE) - events = recording(dir, :create, :oneshot, :mask_create) + recording(dir, :create, :oneshot, :mask_create) expect do recording(dir, :create, :oneshot, :mask_create) end.to raise_error(Errno::EEXIST) From 3055fa175b61eced416f47d5577298d48dae511d Mon Sep 17 00:00:00 2001 From: uvlad7 Date: Mon, 23 Jun 2025 21:11:16 +0300 Subject: [PATCH 13/14] typos --- lib/rb-inotify/notifier.rb | 8 ++++---- rb-inotify.gemspec | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/rb-inotify/notifier.rb b/lib/rb-inotify/notifier.rb index 4a65ab4..5c8ecb4 100644 --- a/lib/rb-inotify/notifier.rb +++ b/lib/rb-inotify/notifier.rb @@ -164,16 +164,16 @@ def to_io # Instead, they specify options for the watcher. # # `:onlydir` - # : Only watch the path if it's a directory; since Linux 2.6.15 + # : Only watch the path if it's a directory; since Linux 2.6.15. # # `:dont_follow` - # : Don't follow symlinks; since Linux 2.6.15 + # : Don't follow symlinks; since Linux 2.6.15. # # `:excl_unlink` - # : Exclude events on unlinked objects; since Linux 2.6.36 + # : Exclude events on unlinked objects; since Linux 2.6.36. # # `:mask_create` - # : Watch pathname only if it does not already have a watch associated with it, Errno::EEXIST is raised otherwise; since Linux 4.18 + # : Watch pathname only if it does not already have a watch associated with it, Errno::EEXIST is raised otherwise; since Linux 4.18. # # `:mask_add` # : Add these flags to the pre-existing flags for this path. diff --git a/rb-inotify.gemspec b/rb-inotify.gemspec index edd9fb9..af24ee8 100644 --- a/rb-inotify.gemspec +++ b/rb-inotify.gemspec @@ -20,7 +20,7 @@ Gem::Specification.new do |spec| spec.required_ruby_version = '>= 2.5' spec.add_dependency "ffi", "~> 1.0" - # Isn't added as a dependency because + # Isn't not added as a dependency because # - It's a default gem on MRI 3.4.2 and TruffleRuby 24.2.1 # - It's not available as a gem on JRuby # spec.add_dependency "etc" From 478b2a20131ed1b68f7f24ca9a97c03a42f49a1e Mon Sep 17 00:00:00 2001 From: uvlad7 Date: Tue, 24 Jun 2025 19:41:36 +0300 Subject: [PATCH 14/14] get rid of kernel version check --- lib/rb-inotify/native/flags.rb | 41 ++++++++++++---------------------- rb-inotify.gemspec | 4 ---- spec/notifier_spec.rb | 2 -- 3 files changed, 14 insertions(+), 33 deletions(-) diff --git a/lib/rb-inotify/native/flags.rb b/lib/rb-inotify/native/flags.rb index d5f2859..bc59607 100644 --- a/lib/rb-inotify/native/flags.rb +++ b/lib/rb-inotify/native/flags.rb @@ -1,5 +1,3 @@ -require "etc" - module INotify module Native # A module containing all the inotify flags @@ -7,12 +5,6 @@ module Native # # @private module Flags - uname = Etc.uname - # JRuby always writes release: 'unknown', but :version contains what :release contains on MRI and TruffleRuby. - release = RUBY_ENGINE == 'jruby' ? uname[:version] : uname[:release] - # give up - release = '0.1.0' unless Gem::Version.correct?(release) - LINUX_KERNEL_VERSION = Gem::Version.new(release) # File was accessed. IN_ACCESS = 0x00000001 # Metadata changed. @@ -52,27 +44,22 @@ module Flags ## Special flags. - if LINUX_KERNEL_VERSION >= Gem::Version.new("2.6.15") - # Do not follow a sym link. - IN_DONT_FOLLOW = 0x02000000 - # Only watch the path if it is a directory. - IN_ONLYDIR = 0x01000000 - end - - if LINUX_KERNEL_VERSION >= Gem::Version.new("2.6.36") - # Exclude events on unlinked objects. - IN_EXCL_UNLINK = 0x04000000 - end - if LINUX_KERNEL_VERSION >= Gem::Version.new("4.18") - # Only create watches. - IN_MASK_CREATE = 0x10000000 - end - + # Do not follow a sym link + # available since Linux 2.6.15, causes EINVAL othervise + IN_DONT_FOLLOW = 0x02000000 + # Exclude events on unlinked objects. + # available since Linux 2.6.36, causes EINVAL othervise + IN_EXCL_UNLINK = 0x04000000 # Add to the mask of an already existing watch. IN_MASK_ADD = 0x20000000 # Only send event once. IN_ONESHOT = 0x80000000 - + # Only watch the path if it is a directory. + # available since Linux 2.6.15, causes EINVAL othervise + IN_ONLYDIR = 0x01000000 + # Only create watches. + # available since Linux 4.18, causes EINVAL othervise + IN_MASK_CREATE = 0x10000000 ## Events sent by the kernel. @@ -80,10 +67,10 @@ module Flags IN_IGNORED = 0x00008000 # Event occurred against dir. IN_ISDIR = 0x40000000 - # Backing fs was unmounted. - IN_UNMOUNT = 0x00002000 # Event queued overflowed. IN_Q_OVERFLOW = 0x00004000 + # Backing fs was unmounted. + IN_UNMOUNT = 0x00002000 EVENT_ONLY_FLAGS = IN_IGNORED | IN_ISDIR | IN_UNMOUNT | IN_Q_OVERFLOW diff --git a/rb-inotify.gemspec b/rb-inotify.gemspec index af24ee8..5ce4bc3 100644 --- a/rb-inotify.gemspec +++ b/rb-inotify.gemspec @@ -20,8 +20,4 @@ Gem::Specification.new do |spec| spec.required_ruby_version = '>= 2.5' spec.add_dependency "ffi", "~> 1.0" - # Isn't not added as a dependency because - # - It's a default gem on MRI 3.4.2 and TruffleRuby 24.2.1 - # - It's not available as a gem on JRuby - # spec.add_dependency "etc" end diff --git a/spec/notifier_spec.rb b/spec/notifier_spec.rb index ffeddad..41b1bad 100644 --- a/spec/notifier_spec.rb +++ b/spec/notifier_spec.rb @@ -42,8 +42,6 @@ end it "ensures that new watches do not modify existing ones" do - skip "too old kernel" unless defined?(INotify::Native::Flags::IN_MASK_CREATE) - recording(dir, :create, :oneshot, :mask_create) expect do recording(dir, :create, :oneshot, :mask_create)