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

Allow to monitor single file #655

Merged
merged 5 commits into from
Apr 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)