Module: Harnex::Inotify

Extended by:
Fiddle::Importer
Defined in:
lib/harnex/watcher/inotify.rb

Constant Summary collapse

IN_ATTRIB =
0x00000004
IN_CLOSE_WRITE =
0x00000008
IN_CREATE =
0x00000100
IN_MOVED_TO =
0x00000080

Class Method Summary collapse

Class Method Details

.available?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/harnex/watcher/inotify.rb', line 23

def available?
  @available
end

.directory_io(path, mask) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/harnex/watcher/inotify.rb', line 27

def directory_io(path, mask)
  raise "inotify is not available on this system" unless available?

  fd = inotify_init
  raise "could not initialize file watch" if fd.negative?

  watch_id = inotify_add_watch(fd, path, mask)
  if watch_id.negative?
    IO.for_fd(fd, autoclose: true)&.close
    raise "could not watch #{path}"
  end

  IO.for_fd(fd, "rb", autoclose: true)
end