From 2d2387716afba2dccd904a48cd6f7ff9b79ee619 Mon Sep 17 00:00:00 2001 From: Johannes Bornhold Date: Sun, 20 Sep 2026 10:46:51 +0200 Subject: [PATCH] Report every changed file in a watched directory at once is_file_changed records each file's mtime as it goes, and is_changed commits those afterwards. Returning at the first changed file left the remaining ones unrecorded, so a directory with N changed files reported one per poll over N polls. The glob path already walks every match. --- livereload/watcher.py | 5 +++-- tests/test_watcher.py | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/livereload/watcher.py b/livereload/watcher.py index 09c3a1b..fc3a0a5 100644 --- a/livereload/watcher.py +++ b/livereload/watcher.py @@ -184,6 +184,7 @@ def is_file_changed(self, path, ignore=None): def is_folder_changed(self, path, ignore=None): """Check if directory path has any changed filepaths.""" + changed = False for root, dirs, files in os.walk(path, followlinks=True): for d in self.ignored_dirs: if d in dirs: @@ -191,8 +192,8 @@ def is_folder_changed(self, path, ignore=None): for f in files: if self.is_file_changed(os.path.join(root, f), ignore): - return True - return False + changed = True + return changed def get_changed_glob_files(self, path, ignore=None): """Check if glob path has any changed filepaths.""" diff --git a/tests/test_watcher.py b/tests/test_watcher.py index 07ee21c..2308283 100644 --- a/tests/test_watcher.py +++ b/tests/test_watcher.py @@ -47,6 +47,22 @@ def test_watch_dir(self): assert watcher.is_changed(tmpdir) assert watcher.is_changed(tmpdir) is False + def test_watch_dir_reports_every_changed_file_at_once(self): + watcher = Watcher() + watcher._start -= 1 + + watcher.watch(tmpdir) + assert watcher.examine() == (None, None) + + for name in ('foo', 'bar', 'baz'): + with open(os.path.join(tmpdir, name), 'w') as f: + f.write('') + + reported, delay = watcher.examine() + assert reported is not None + assert delay is None + assert watcher.examine() == (None, None) + def test_watch_file(self): watcher = Watcher() watcher.count = 0