Fix watcher sync loop when auto-watch is enabled
This commit is contained in:
+17
-3
@@ -21,6 +21,11 @@ class PlaylistEventHandler(FileSystemEventHandler):
|
||||
|
||||
if event.is_directory:
|
||||
return
|
||||
|
||||
# For moved events, the interesting path is the destination.
|
||||
event_path = getattr(event, "dest_path", None) if event.event_type == "moved" else event.src_path
|
||||
if not event_path:
|
||||
return
|
||||
|
||||
# Filter out noisy events. Only listen to actual changes.
|
||||
# 'opened' and 'closed' (without write) are read events and should be ignored.
|
||||
@@ -28,16 +33,25 @@ class PlaylistEventHandler(FileSystemEventHandler):
|
||||
return
|
||||
|
||||
# Ignore temporary files or hidden files
|
||||
filename = os.path.basename(event.src_path)
|
||||
filename = os.path.basename(event_path)
|
||||
if filename.startswith('.'):
|
||||
return
|
||||
|
||||
# Only watch playlist files to avoid noisy triggers.
|
||||
if not filename.lower().endswith((".m3u", ".m3u8")):
|
||||
return
|
||||
|
||||
# Prevent feedback loops: if sync is in progress, ignore events
|
||||
if sync_manager.is_syncing:
|
||||
logger.debug(f"[Watcher] Ignoring event {event.event_type} on {event.src_path} because sync is in progress.")
|
||||
logger.debug(f"[Watcher] Ignoring event {event.event_type} on {event_path} because sync is in progress.")
|
||||
return
|
||||
|
||||
logger.info(f"[Watcher] Accepted file change: {event.event_type} {event.src_path}")
|
||||
# Prevent feedback loops: ignore events right after sync writes/deletes.
|
||||
if getattr(sync_manager, "is_watcher_suppressed", False):
|
||||
logger.debug(f"[Watcher] Ignoring event {event.event_type} on {event_path} because watcher is suppressed.")
|
||||
return
|
||||
|
||||
logger.info(f"[Watcher] Accepted file change: {event.event_type} {event_path}")
|
||||
self.trigger_sync()
|
||||
|
||||
def trigger_sync(self):
|
||||
|
||||
Reference in New Issue
Block a user