class Listen::Adapter::Linux

@see github.com/nex3/rb-inotify

Constants

DEFAULTS
OS_REGEXP
README_URL

Private Instance Methods

_change(event_flags) click to toggle source
# 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
_configure(directory, &callback) click to toggle source
# 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) click to toggle source
# File lib/listen/adapter/linux.rb, line 97
def _dir_event?(event)
  event.flags.include?(:isdir)
end
_process_event(dir, event) click to toggle source

rubocop:disable Metrics/MethodLength

# File lib/listen/adapter/linux.rb, line 42
def _process_event(dir, event)
  # NOTE: avoid using event.absolute_name since new API
  # will need to have a custom recursion implemented
  # to properly match events to configured directories
  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 }

  # Note: don't pass options to force rescanning the directory, so we can
  # detect moving/deleting a whole tree
  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() click to toggle source
# File lib/listen/adapter/linux.rb, line 37
def _run
  @worker.run
end
_skip_event?(event) click to toggle source

rubocop:enable Metrics/MethodLength

# File lib/listen/adapter/linux.rb, line 76
def _skip_event?(event)
  # Event on root directory
  return true if event.name == ''
  # INotify reports changes to files inside directories as events
  # on the directories themselves too.
  #
  # @see http://linux.die.net/man/7/inotify
  _dir_event?(event) && (event.flags & [:close, :modify]).any?
end
_stop() click to toggle source
Calls superclass method Listen::Adapter::Base#_stop
# File lib/listen/adapter/linux.rb, line 101
def _stop
  @worker&.close

  super
end