Skip to content

Commit

Permalink
[inotify] Allow to monitor single file (gorakhargosh#655)
Browse files Browse the repository at this point in the history
Co-authored-by: ruanbonan <ruanbonan@intra.nsfocus.com>
  • Loading branch information
brant-ruan and ruanbonan committed Apr 28, 2020
1 parent 6fdbe3e commit 4df087a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
3 changes: 2 additions & 1 deletion changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ Changelog

2020-0x-xx • `full history <https://github.com/gorakhargosh/watchdog/compare/v0.10.2...master>`__

- Thanks to our beloved contributors: @
- [inotify] Allow to monitor single file (`#655 <https://github.com/gorakhargosh/watchdog/pull/655>`__)
- Thanks to our beloved contributors: @brant-ruan


0.10.2
Expand Down
5 changes: 4 additions & 1 deletion src/watchdog/observers/inotify_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions tests/test_inotify_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 4df087a

Please sign in to comment.