Skip to content
Merged
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
15 changes: 12 additions & 3 deletions src/recallforge/watch_folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,17 @@ def _build_snapshot(self, config: WatchConfig) -> Dict[str, Tuple[int, int, int]
continue
return snap

def _scanner_loop(self, watch_id: str) -> None:
def _scanner_loop(
self,
watch_id: str,
initial_snapshot: Optional[Dict[str, Tuple[int, int, int]]] = None,
) -> None:
config = WatchConfig.from_dict(self.watches[watch_id]["config"])
root = Path(config.folder_path).expanduser().resolve()
queue = self.queues[watch_id]
evt = self.running[watch_id]

prev = self._build_snapshot(config)
prev = dict(initial_snapshot or self._build_snapshot(config))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve empty initial snapshot when starting scanner

When the watched folder is empty at startup, initial_snapshot is {} (falsy), so initial_snapshot or self._build_snapshot(config) performs a second snapshot in the scanner thread. Any file created between start_watch() taking the first snapshot and this second snapshot is treated as already present in prev, so no created event is emitted for it. This reintroduces the startup race for the common empty-directory case the change is trying to fix.

Useful? React with 👍 / 👎.

while evt.is_set():
current = self._build_snapshot(config)

Expand Down Expand Up @@ -349,8 +353,13 @@ def start_watch(self, config: WatchConfig) -> str:
self.queues[watch_id] = Queue()
self.running[watch_id] = threading.Event()
self.running[watch_id].set()
initial_snapshot = self._build_snapshot(config)

s = threading.Thread(target=self._scanner_loop, args=(watch_id,), daemon=True)
s = threading.Thread(
target=self._scanner_loop,
args=(watch_id, initial_snapshot),
daemon=True,
)
w = threading.Thread(target=self._worker_loop, args=(watch_id,), daemon=True)
s.start()
w.start()
Expand Down
Loading