From 9dd0797f4935c58000fe01c4a5773e587964d1cd Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Wed, 24 Nov 2021 07:57:07 -0500 Subject: [PATCH] file_manager: ignore duplicate "create_file" notifications for gcode files The the cancel object post processor results in an additional "create_file" notification when the old file is replaced. Track previous "create_file" notifications for valid gcode files so the dups can be suppressed. Signed-off-by: Eric Callahan --- .../components/file_manager/file_manager.py | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/moonraker/components/file_manager/file_manager.py b/moonraker/components/file_manager/file_manager.py index a14c2fc..d700bef 100644 --- a/moonraker/components/file_manager/file_manager.py +++ b/moonraker/components/file_manager/file_manager.py @@ -998,7 +998,11 @@ class NotifySyncLock: if not self.check_need_sync(path): return self.notified_paths.add(path) - if self.wait_fut is not None and self.dest_path == path: + if ( + self.wait_fut is not None and + not self.wait_fut.done() and + self.dest_path == path + ): self.wait_fut.set_result(None) # Transfer control to waiter try: @@ -1041,6 +1045,7 @@ class INotifyHandler: self.watched_nodes: Dict[int, InotifyNode] = {} self.pending_moves: Dict[ int, Tuple[InotifyNode, str, asyncio.Handle]] = {} + self.create_gcode_notifications: Dict[str, Any] = {} def add_root_watch(self, root: str, root_path: str) -> None: @@ -1321,6 +1326,22 @@ class INotifyHandler: is_valid = False elif action not in ["delete_file", "delete_dir"]: is_valid = False + ext = os.path.splitext(rel_path)[-1].lower() + if ( + is_valid and + root == "gcodes" and + ext in VALID_GCODE_EXTS and + action == "create_file" + ): + prev_info = self.create_gcode_notifications.get(rel_path, {}) + if file_info == prev_info: + logging.debug("Ignoring duplicate 'create_file' " + f"notification: {rel_path}") + is_valid = False + else: + self.create_gcode_notifications[rel_path] = dict(file_info) + elif rel_path in self.create_gcode_notifications: + del self.create_gcode_notifications[rel_path] file_info['path'] = rel_path file_info['root'] = root result = {'action': action, 'item': file_info}