Class: Listen::Adapter::Linux
- Inherits:
-
Base
- Object
- Base
- Listen::Adapter::Linux
show all
- Defined in:
- lib/listen/adapter/linux.rb
Overview
Constant Summary
collapse
- OS_REGEXP =
/linux/i
- DEFAULTS =
{
events: [
:recursive,
:attrib,
:create,
:modify,
:delete,
:move,
:close_write
],
wait_for_delay: 0.1
}.freeze
- README_URL =
'https://github.com/guard/listen'\
'/blob/master/README.md#increasing-the-amount-of-inotify-watchers'
Instance Attribute Summary
Attributes inherited from Base
#config, #options
Instance Method Summary
collapse
Methods inherited from Base
#_log_exception, #_queue_change, #_timed, #configure, #initialize, #start, #started?, #stop, usable?
Instance Method Details
#_change(event_flags) ⇒ Object
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/listen/adapter/linux.rb', line 86
def _change(event_flags)
{ modified: [:attrib, :close_write],
moved_to: [:moved_to],
moved_from: [:moved_from],
added: [:create],
removed: [:delete] }.each do |change, flags|
return change unless (flags & event_flags).empty?
end
nil
end
|
27
28
29
30
31
32
33
34
35
|
# File 'lib/listen/adapter/linux.rb', line 27
def _configure(directory, &callback)
require 'rb-inotify'
@worker ||= ::INotify::Notifier.new
@worker.watch(directory.to_s, *options.events, &callback)
rescue Errno::ENOSPC
raise ::Listen::Error::INotifyMaxWatchesExceeded, <<~EOS
Unable to monitor directories for changes because iNotify max watches exceeded. See #{README_URL} .
EOS
end
|
#_dir_event?(event) ⇒ Boolean
97
98
99
|
# File 'lib/listen/adapter/linux.rb', line 97
def _dir_event?(event)
event.flags.include?(:isdir)
end
|
#_process_event(dir, event) ⇒ Object
rubocop:disable Metrics/MethodLength
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/listen/adapter/linux.rb', line 42
def _process_event(dir, event)
path = Pathname.new(event.watcher.path) + event.name
rel_path = path.relative_path_from(dir).to_s
Listen.logger.debug { "inotify: #{rel_path} (#{event.flags.inspect})" }
if /1|true/ =~ ENV['LISTEN_GEM_SIMULATE_FSEVENT']
if (event.flags & [:moved_to, :moved_from]) || _dir_event?(event)
rel_path = path.dirname.relative_path_from(dir).to_s
end
_queue_change(:dir, dir, rel_path, {})
return
end
return if _skip_event?(event)
cookie_params = event.cookie.zero? ? {} : { cookie: event.cookie }
if _dir_event?(event)
_queue_change(:dir, dir, rel_path, cookie_params)
return
end
params = cookie_params.merge(change: _change(event.flags))
_queue_change(:file, dir, rel_path, params)
end
|
#_run ⇒ Object
37
38
39
|
# File 'lib/listen/adapter/linux.rb', line 37
def _run
@worker.run
end
|
#_skip_event?(event) ⇒ Boolean
rubocop:enable Metrics/MethodLength
76
77
78
79
80
81
82
83
84
|
# File 'lib/listen/adapter/linux.rb', line 76
def _skip_event?(event)
return true if event.name == ''
_dir_event?(event) && (event.flags & [:close, :modify]).any?
end
|
#_stop ⇒ Object
101
102
103
104
105
|
# File 'lib/listen/adapter/linux.rb', line 101
def _stop
@worker&.close
super
end
|