Inotify
objects are used for monitoring file system events, it can monitor individual files or directories. When a directory is monitored it will return events for the directory itself and all files inside the directory.
Inotify
IO objects can be watched using IO.select or Epoll. IO#close may be called on the object when it is no longer needed.
Inotify
is available on Linux 2.6.13 or later.
require "sleepy_penguin/sp" ino = SP::Inotify.new ino.add_watch("/path/to/foo", :OPEN) ino.each do |event| p event.events # => [ :OPEN ] end
Inotify.new([flags]) -> Inotify IO object source
Flags may be any of the following as an Array of Symbols or Integer mask:
:NONBLOCK - sets the non-blocking flag on the descriptor watched.
:CLOEXEC - sets the close-on-exec flag
ino.add_watch(path, flags) -> Integer source
Adds a watch on an object specified by its mask
, returns an unsigned Integer watch descriptor. flags
may be a mask of the following Inotify
constants or array of their symbolic names.
:ACCESS - File was accessed (read) (*)
:ATTRIB - Metadata changed.
:CLOSE_WRITE - File opened for writing was closed (*)
:CLOSE_NOWRITE - File not opened for writing was closed (*)
:CREATE - File/directory created in watched directory (*)
:DELETE - File/directory deleted from watched directory (*)
:DELETE_SELF - Watched file/directory was itself deleted
:MODIFY - File was modified (*)
:MOVE_SELF - Watched file/directory was itself moved
:MOVED_FROM - File moved out of watched directory (*)
:MOVED_TO - File moved into watched directory (*)
:OPEN - File was opened (*)
When monitoring a directory, the events marked with an asterisk (*) above can occur for files in the directory, in which case the name field in the Event
structure identifies the name of the file in the directory.
Shortcut flags:
:ALL_EVENTS - a bitmask of all the above events
:MOVE - :MOVED_FROM or :MOVED_TO
:CLOSE - :CLOSE_WRITE or :CLOSE_NOWRITE
The following watch attributes may also be included in flags:
:DONT_FOLLOW - don't dereference symlinks (since Linux 2.6.15)
:EXCL_UNLINK - don't generate unlink events for children (since 2.6.36)
:MASK_ADD - add events to an existing watch mask if it exists
:ONESHOT - monitor for one event and then remove it from the watch
:ONLYDIR - only watch the pathname if it is a directory
ino.each { |event| ... } -> ino source
Yields each Inotify::Event
received in a blocking fashion.
ino.rm_watch(watch_descriptor) -> 0 source
Removes a watch based on a watch descriptor Integer. The watch descriptor is a return value given by Inotify#add_watch
ino.take([nonblock]) -> Inotify::Event or nil source
Returns the next Inotify::Event
processed. May return nil
if nonblock
is true
.
Parent: IO
Pages
Classes
Methods
mail archives: https://yhbt.net/sleepy-penguin/ public: sleepy-penguin@yhbt.net source code: git clone https://yhbt.net/sleepy_penguin.git