Skip to content

Recursive inotify monitoring fails on inaccessible directories #670

Description

@nomis

Using version 0.10.2:

$ watchmedo log --recursive /path
Traceback (most recent call last):
  File ".local/bin/watchmedo", line 11, in <module>
    sys.exit(main())
  File "/home/user/.local/lib/python3.6/site-packages/watchdog/watchmedo.py", line 576, in main
    parser.dispatch()
  File "/home/user/.local/lib/python3.6/site-packages/argh/helpers.py", line 55, in dispatch
    return dispatch(self, *args, **kwargs)
  File "/home/user/.local/lib/python3.6/site-packages/argh/dispatching.py", line 174, in dispatch
    for line in lines:
  File "/home/user/.local/lib/python3.6/site-packages/argh/dispatching.py", line 277, in _execute_command
    for line in result:
  File "/home/user/.local/lib/python3.6/site-packages/argh/dispatching.py", line 231, in _call
    result = function(namespace_obj)
  File "/home/user/.local/lib/python3.6/site-packages/watchdog/watchmedo.py", line 350, in log
    observe_with(observer, handler, args.directories, args.recursive)
  File "/home/user/.local/lib/python3.6/site-packages/watchdog/watchmedo.py", line 116, in observe_with
    observer.start()
  File "/home/user/.local/lib/python3.6/site-packages/watchdog/observers/api.py", line 253, in start
    emitter.start()
  File "/home/user/.local/lib/python3.6/site-packages/watchdog/utils/__init__.py", line 110, in start
    self.on_thread_start()
  File "/home/user/.local/lib/python3.6/site-packages/watchdog/observers/inotify.py", line 121, in on_thread_start
    self._inotify = InotifyBuffer(path, self.watch.is_recursive)
  File "/home/user/.local/lib/python3.6/site-packages/watchdog/observers/inotify_buffer.py", line 35, in __init__
    self._inotify = Inotify(path, recursive)
  File "/home/user/.local/lib/python3.6/site-packages/watchdog/observers/inotify_c.py", line 200, in __init__
    self._add_dir_watch(path, recursive, event_mask)
  File "/home/user/.local/lib/python3.6/site-packages/watchdog/observers/inotify_c.py", line 395, in _add_dir_watch
    self._add_watch(full_path, mask)
  File "/home/user/.local/lib/python3.6/site-packages/watchdog/observers/inotify_c.py", line 409, in _add_watch
    Inotify._raise_error()
  File "/home/user/.local/lib/python3.6/site-packages/watchdog/observers/inotify_c.py", line 425, in _raise_error
    raise OSError(err, os.strerror(err))
PermissionError: [Errno 13] Permission denied

There is a directory under /path that the current user does not have read or execute permission for.

The error is raised within watchdog itself so there's no way to ignore this in the event handler. There's no exception raised if an inaccessible directory is created (umask 0777; mkdir test) on a path that is already being recursively monitored (although it won't start monitoring inside it if its permissions are later changed).

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions