fix: Only trigger Immich scan on file events

Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
2025-12-17 11:15:31 -07:00
parent a92c0464d2
commit d811483e94

16
main.py
View File

@@ -57,6 +57,7 @@ def main():
while True: while True:
events = inotify.read(timeout=1000) events = inotify.read(timeout=1000)
if events: if events:
scan_needed = False
for event in events: for event in events:
logging.debug(f"Event: {event!r}") logging.debug(f"Event: {event!r}")
if event.mask & flags.IGNORED: if event.mask & flags.IGNORED:
@@ -76,12 +77,15 @@ def main():
add_watch_recursive(inotify, new_dir_path, watch_flags, wd_to_path) add_watch_recursive(inotify, new_dir_path, watch_flags, wd_to_path)
continue continue
if timer: scan_needed = True
timer.cancel()
logging.info('Debounce cancelled timer.') if scan_needed:
timer = threading.Timer(SCAN_DELAY_SECONDS, trigger_scan) if timer:
timer.start() timer.cancel()
logging.info(f"Modification detected. Triggering scan in {SCAN_DELAY_SECONDS} seconds.") logging.info('Debounce cancelled timer.')
timer = threading.Timer(SCAN_DELAY_SECONDS, trigger_scan)
timer.start()
logging.info(f"Modification detected. Triggering scan in {SCAN_DELAY_SECONDS} seconds.")
except KeyboardInterrupt: except KeyboardInterrupt:
logging.info("Shutting down...") logging.info("Shutting down...")
finally: finally: