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

Force FSEvents to use recursive mode to ensure that events are delivered #1013

Open
wants to merge 4 commits 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/watchdog/observers/fsevents.py
Expand Up @@ -337,9 +337,12 @@ class FSEventsObserver(BaseObserver):
def __init__(self, timeout=DEFAULT_OBSERVER_TIMEOUT):
super().__init__(emitter_class=FSEventsEmitter, timeout=timeout)

def schedule(self, event_handler, path, recursive=False):
def schedule(self, event_handler, path, recursive=True):
# Fix for issue #26: Trace/BPT error when given a unicode path
# string. https://github.com/gorakhargosh/watchdog/issues#issue/26
if isinstance(path, str):
path = unicodedata.normalize("NFC", path)
return BaseObserver.schedule(self, event_handler, path, recursive)
if not recursive:
import warnings
warnings.warn("FSEvents requires and assumes recursive=True")
BoboTiG marked this conversation as resolved.
Show resolved Hide resolved
return BaseObserver.schedule(self, event_handler, path, recursive=True)
10 changes: 8 additions & 2 deletions tests/test_fsevents.py
Expand Up @@ -78,7 +78,7 @@ def test_add_watch_twice(observer: BaseObserver, p: P) -> None:
a = p("a")
mkdir(a)
h = FileSystemEventHandler()
w = ObservedWatch(a, recursive=False)
w = ObservedWatch(a, recursive=True)

def callback(path, inodes, flags, ids):
pass
Expand Down Expand Up @@ -219,7 +219,7 @@ def on_thread_stop(self):
"""
a = p("a")
mkdir(a)
w = observer.schedule(FileSystemEventHandler(), a, recursive=False)
w = observer.schedule(FileSystemEventHandler(), a)
rmdir(a)
time.sleep(0.1)
observer.unschedule(w)
Expand Down Expand Up @@ -327,3 +327,9 @@ def on_any_event(self, event):
observer.unschedule(watch)
observer.stop()
observer.join(1)

def test_watchdog_assumes_recursive(p: P) -> None:
"""See https://github.com/gorakhargosh/watchdog/issues/918"""
observer = Observer()
w = observer.schedule(FileSystemEventHandler(), ".")
assert w.is_recursive, "FSEvents should assume recursive mode"