From d3df568aecab3cd36d66c2d17318b737cda86228 Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Fri, 18 Jun 2021 06:15:54 -0400 Subject: [PATCH] extract_metadata: don't remove ufp files after failed extraction Cura writes ufp files in chunks, closing the file after each chunk is written. This will result in a failed extraction, and removing the file will result in corruption. Signed-off-by: Eric Callahan --- scripts/extract_metadata.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/scripts/extract_metadata.py b/scripts/extract_metadata.py index 10f36b1..39cbdca 100644 --- a/scripts/extract_metadata.py +++ b/scripts/extract_metadata.py @@ -704,11 +704,13 @@ def extract_ufp(ufp_path: str, dest_path: str) -> None: if not os.path.exists(dest_thumb_dir): os.mkdir(dest_thumb_dir) shutil.move(tmp_thumb_path, dest_thumb_path) - finally: - try: - os.remove(ufp_path) - except Exception: - log_to_stderr(f"Error removing ufp file: {ufp_path}") + except Exception: + log_to_stderr(traceback.format_exc()) + sys.exit(-1) + try: + os.remove(ufp_path) + except Exception: + log_to_stderr(f"Error removing ufp file: {ufp_path}") def main(path: str, filename: str, ufp: Optional[str]) -> None: file_path = os.path.join(path, filename)