diff --git a/src/watchdog/observers/fsevents.py b/src/watchdog/observers/fsevents.py index c3b29cd0..55c0ffcd 100644 --- a/src/watchdog/observers/fsevents.py +++ b/src/watchdog/observers/fsevents.py @@ -324,10 +324,16 @@ class FSEventsObserver(BaseObserver): def __init__(self, timeout=DEFAULT_OBSERVER_TIMEOUT): super().__init__(FSEventsEmitter, timeout=timeout) - def schedule(self, event_handler, path, recursive=False, event_filter=None): + def schedule(self, event_handler, path, recursive=True, event_filter=None): # 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) + if not recursive: + import warnings + + warnings.warn("FSEvents requires and assumes recursive=True") + recursive = True + return super().schedule(event_handler, path, recursive=recursive, event_filter=event_filter) diff --git a/tests/test_fsevents.py b/tests/test_fsevents.py index 540fb3b3..3a1623d0 100644 --- a/tests/test_fsevents.py +++ b/tests/test_fsevents.py @@ -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 @@ -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) @@ -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"