From 9c768758967c5d225c713fe9db2bbdacff5635d8 Mon Sep 17 00:00:00 2001 From: Arksine Date: Wed, 5 Aug 2020 14:02:06 -0400 Subject: [PATCH] file_manager: use print_stats to determine if an operation is safe Signed-off-by: Eric Callahan --- moonraker/plugins/file_manager.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/moonraker/plugins/file_manager.py b/moonraker/plugins/file_manager.py index f0a0c62..4b2ceae 100644 --- a/moonraker/plugins/file_manager.py +++ b/moonraker/plugins/file_manager.py @@ -143,21 +143,23 @@ class FileManager: async def _handle_operation_check(self, requested_path): # Get virtual_sdcard status request = self.server.make_request( - "objects/status", 'GET', {'virtual_sdcard': []}) + "objects/status", 'GET', {'print_stats': []}) result = await request.wait() if isinstance(result, self.server.error): raise result - vsd = result.get('virtual_sdcard', {}) - loaded_file = vsd.get('filename', "") + pstats = result.get('print_stats', {}) + loaded_file = pstats.get('filename', "") + state = pstats.get('state', "") gc_path = self.file_paths.get('gcodes', "") full_path = os.path.join(gc_path, loaded_file) - if os.path.isdir(requested_path): - # Check to see of the loaded file is in the reques - if full_path.startswith(requested_path): + if loaded_file and state != "complete": + if os.path.isdir(requested_path): + # Check to see of the loaded file is in the request + if full_path.startswith(requested_path): + raise self.server.error("File currently in use", 403) + elif full_path == requested_path: raise self.server.error("File currently in use", 403) - elif full_path == requested_path: - raise self.server.error("File currently in use", 403) - ongoing = vsd.get('total_duration', 0.) > 0. + ongoing = state in ["printing", "paused"] return ongoing def _convert_path(self, url_path):