diff --git a/changelog.rst b/changelog.rst index adb3d7be0..5a23523c2 100644 --- a/changelog.rst +++ b/changelog.rst @@ -8,7 +8,8 @@ Changelog 2020-0x-xx • `full history `__ -- Thanks to our beloved contributors: @ +- [inotify] Allow to monitor single file (`#655 `__) +- Thanks to our beloved contributors: @brant-ruan 0.10.2 diff --git a/src/watchdog/observers/inotify_c.py b/src/watchdog/observers/inotify_c.py index 1eae3272b..f70f8da00 100644 --- a/src/watchdog/observers/inotify_c.py +++ b/src/watchdog/observers/inotify_c.py @@ -197,7 +197,10 @@ def __init__(self, path, recursive=False, event_mask=WATCHDOG_ALL_EVENTS): self._path = path self._event_mask = event_mask self._is_recursive = recursive - self._add_dir_watch(path, recursive, event_mask) + if os.path.isdir(path): + self._add_dir_watch(path, recursive, event_mask) + else: + self._add_watch(path, event_mask) self._moved_from_events = dict() @property diff --git a/tests/test_inotify_c.py b/tests/test_inotify_c.py index 3de1853da..b4d9f9fc6 100644 --- a/tests/test_inotify_c.py +++ b/tests/test_inotify_c.py @@ -168,3 +168,13 @@ def test_non_ascii_path(): assert event.src_path == path # Just make sure it doesn't raise an exception. assert repr(event) + + +def test_watch_file(): + path = p("this_is_a_file") + with open(path, "a"): + pass + with watching(path): + os.remove(path) + event, _ = event_queue.get(timeout=5) + assert repr(event)