Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Listen crashes on inaccessable directories (Errno::EACCES) #251

Closed
kansaichris opened this issue Sep 5, 2014 · 3 comments
Closed

Listen crashes on inaccessable directories (Errno::EACCES) #251

kansaichris opened this issue Sep 5, 2014 · 3 comments
Labels

Comments

@kansaichris
Copy link

Given the following very basic program (let's call it test.rb):

require 'listen'

listener = Listen.to('.', :ignore => [/test/]) do |modified, added, removed|
  puts "Something changed!"
end

listener.start
sleep

Also given the following output from ls -l:

total 8
drwx------  2 root   staff   68 Sep  5 16:02 test
-rw-r--r--  1 chris  staff  149 Sep  5 16:10 test.rb

The program will crash with the following error when run:

E, [2014-09-05T16:11:49.509781 #86974] ERROR -- : Actor crashed!
Errno::EACCES: Permission denied @ dir_initialize

This is despite the fact that [/test/] was given as the :ignore parameter to Listen.to!

The culprit appears to be a call to Dir.entries in the _fast_build method:

def _fast_build(root)
  @paths[root] = _auto_hash
  left = Queue.new
  left << '.'

  while !left.empty?
    dirname = left.pop
    add_dir(root, dirname)

    path = ::File.join(root, dirname)
    current = Dir.entries(path.to_s) - %w(. ..)

    current.each do |entry|
      full_path = ::File.join(path, entry)

      if Dir.exist?(full_path)
        left << (dirname == '.' ? entry : ::File.join(dirname, entry))
      else
        begin
          lstat = ::File.lstat(full_path)
          data = { mtime: lstat.mtime.to_f, mode: lstat.mode }
          _fast_update_file(root, dirname, entry, data)
        rescue SystemCallError
          _fast_unset_path(root, dirname, entry)
        end
      end
    end
  end
end

Why does Listen have to call Dir.entries on ignored directories? Shouldn't those be excluded?

@kansaichris
Copy link
Author

@parkr @gjtorikian Just putting this on your radar...

@e2
Copy link
Contributor

e2 commented Sep 14, 2014

"ignore" in listen doesn't mean "skip scanning this folder", it means only "don't report" (Honestly, it depends on the adapter, e.g. polling actually should skip the folder).

The problem here is that I didn't consider someone would have an inaccessible folder being watched.

It's probably enough to add a test case for this and wrap the Dir.entries within a SystemCallError rescue block.

The best solution - if you're e.g. testing permissions - is to not watch those folders (since you don't have access, there's no point anyway). Again, ignoring has nothing to do with this.

I might get to this, but it's not a top priority right now - but don't hesitate to take a stab at a PR and ask for review/info.

@e2 e2 added the bug label Oct 18, 2014
@e2 e2 changed the title Listen crashes on ignored directories Listen crashes on inaccessable directories Nov 15, 2014
@e2
Copy link
Contributor

e2 commented Nov 15, 2014

2 different issues here:

  1. optimized backends in Listen don't ignore directories (feature request: Feature request: Listen could *really ignore* ignored directories (optimization) #274)
  2. almost every tool out there crashes/errors out/exits by design on permission errors

Listen doesn't crash any more (fixed on master), but to prevent rb-inotify from crashing for the same reason, #274 has to be implemented

So I'm closing this (no bug to fix in Listen itself).

Workarounds

  1. avoid watching directories which have permission problems (very reasonable)
  2. use polling - it's the only backend that really ignores directories (fix on master is needed, though - soon to be released)

Best solution

Getting #274 implemented of course - since everyone benefits
(PRs are more than welcome - I'll be glad to help, answer questions, etc.).

@e2 e2 closed this as completed Nov 15, 2014
@e2 e2 changed the title Listen crashes on inaccessable directories Listen crashes on inaccessable directories (Errno::EACCES) Nov 15, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants