diff mbox series

[master-next,2/2] runqemu: refactor a duplicated cleanup statement

Message ID 20250806155549.3395012-2-yoann.congal@smile.fr
State New
Headers show
Series [master-next,1/2] runqemu: use "zstd -o" to preserve sparse images | expand

Commit Message

Yoann Congal Aug. 6, 2025, 3:55 p.m. UTC
From: Yoann Congal <yoann.congal@smile.fr>

Refactor using a "finally:" instead of a duplicated statement inside and
outside of the try/except block.

Signed-off-by: Yoann Congal <yoann.congal@smile.fr>
---
 scripts/runqemu | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/scripts/runqemu b/scripts/runqemu
index 4fb85177e3..3a339acc2a 100755
--- a/scripts/runqemu
+++ b/scripts/runqemu
@@ -450,11 +450,10 @@  class BaseConfig(object):
             try:
                 subprocess.check_call(['zstd', '-d', image_path, '-o', uncompressed_path])
             except subprocess.CalledProcessError as e:
-                self.cleanup_files.append(uncompressed_path)
                 raise RunQemuError(f"Failed to decompress {self.rootfs}: {e}")
-    
-            # Mark for deletion at the end
-            self.cleanup_files.append(uncompressed_path)
+            finally:
+                # Mark temporary file for deletion
+                self.cleanup_files.append(uncompressed_path)
     
         # Use the decompressed image as the rootfs
         self.rootfs = uncompressed_path