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 watching a file that didn't exist before #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion aionotify/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ def watch(self, path, flags, *, alias=None):
alias = path
if alias in self.requests:
raise ValueError("A watch request is already scheduled for alias %s" % alias)
self.requests[alias] = (path, flags)
if self._fd is not None:
# We've started, register the watch immediately.
self._setup_watch(alias, path, flags)
self.requests[alias] = (path, flags)

def unwatch(self, alias):
"""Stop watching a given rule."""
Expand Down
14 changes: 14 additions & 0 deletions tests/test_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,20 @@ def test_rename_detection(self):
# And it's over.
yield from self._assert_no_events()

@asyncio.coroutine
def test_watch_after_created(self):
"""It should be possible to retry watching a file that didn't exist."""
yield from self.watcher.setup(self.loop)

full_path = os.path.join(self.testdir, 'a')
with self.assertRaises(OSError):
self.watcher.watch(full_path, aionotify.Flags.MODIFY)

self._touch('a')
self.watcher.watch(full_path, aionotify.Flags.MODIFY)

yield from self._assert_no_events()


class ErrorTests(AIONotifyTestCase):
"""Test error cases."""
Expand Down