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 5 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/watchdog/observers/fsevents.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
BoboTiG marked this conversation as resolved.
Show resolved Hide resolved
recursive = True

return super().schedule(event_handler, path, recursive=recursive, event_filter=event_filter)
10 changes: 8 additions & 2 deletions tests/test_fsevents.py
Original file line number Diff line number Diff line change
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"
Loading