Skip to content

Commit

Permalink
Force FSEvents to use recursive mode to ensure that events are delivered
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosuav committed Oct 9, 2023
1 parent 5f9d93c commit 4eca238
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/watchdog/observers/fsevents.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,11 @@ 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:
warnings.warn("FSEvents requires and assumes recursive=True")
return BaseObserver.schedule(self, event_handler, path, recursive=True)
6 changes: 6 additions & 0 deletions tests/test_fsevents.py
Original file line number Diff line number Diff line change
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"

0 comments on commit 4eca238

Please sign in to comment.