Class: Listen::Adapters::Linux

Inherits:
Listen::Adapter show all
Extended by:
DependencyManager
Defined in:
lib/listen/adapters/linux.rb

Overview

Listener implementation for Linux ‘inotify`.

Constant Summary collapse

EVENTS =

Watched inotify events

%w[recursive attrib create delete move close_write]
INOTIFY_LIMIT_MESSAGE =

The message to show when the limit of inotify watchers is not enough

<<-EOS.gsub(/^\s*/, '')
  Listen error: unable to monitor directories for changes.

  Please head to https://github.com/guard/listen/wiki/Increasing-the-amount-of-inotify-watchers
  for information on how to solve this issue.
EOS

Constants included from DependencyManager

DependencyManager::BUNDLER_DECLARE_GEM, DependencyManager::GEM_INSTALL_COMMAND, DependencyManager::GEM_LOAD_MESSAGE

Constants inherited from Listen::Adapter

Listen::Adapter::DEFAULT_LATENCY, Listen::Adapter::MISSING_DEPENDENCY_MESSAGE, Listen::Adapter::POLLING_FALLBACK_MESSAGE

Instance Attribute Summary

Attributes inherited from Listen::Adapter

#directories, #latency, #paused

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DependencyManager

add_loaded, already_loaded?, clear_loaded, dependencies_loaded?, dependency, extended, load_depenencies

Methods inherited from Listen::Adapter

#report_changes, select_and_initialize, #started?, usable_and_works?, #wait_for_callback, #wait_for_changes, works?

Constructor Details

#initialize(directories, options = {}, &callback) ⇒ Linux

Initializes the Adapter. See Listen::Adapter#initialize for more info.



30
31
32
33
34
35
# File 'lib/listen/adapters/linux.rb', line 30

def initialize(directories, options = {}, &callback)
  super
  @worker = init_worker
rescue Errno::ENOSPC
  abort(INOTIFY_LIMIT_MESSAGE)
end

Class Method Details

.usable?Boolean

Checks if the adapter is usable on the current OS.

Returns:

  • (Boolean)

    whether usable or not



70
71
72
73
# File 'lib/listen/adapters/linux.rb', line 70

def self.usable?
  return false unless RbConfig::CONFIG['target_os'] =~ /linux/i
  super
end

Instance Method Details

#start(blocking = true) ⇒ Object

Starts the adapter.

Parameters:

  • blocking (Boolean) (defaults to: true)

    whether or not to block the current thread after starting



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/listen/adapters/linux.rb', line 41

def start(blocking = true)
  @mutex.synchronize do
    return if @stop == false
    super
  end

  @worker_thread = Thread.new { @worker.run }
  @poll_thread   = Thread.new { poll_changed_dirs } if @report_changes

  @worker_thread.join if blocking
end

#stopObject

Stops the adapter.



55
56
57
58
59
60
61
62
63
64
# File 'lib/listen/adapters/linux.rb', line 55

def stop
  @mutex.synchronize do
    return if @stop == true
    super
  end

  @worker.stop
  Thread.kill(@worker_thread) if @worker_thread
  @poll_thread.join if @poll_thread
end