diff mbox series

[2/3] runqemu: Also remove file when copy failed

Message ID 20261107-mathieu-master-next-b16487-v1-2-2fe0e7b9b1fb@bootlin.com
State New
Headers show
Series runqemu: Fix a deadlock resulting in files left behind | expand

Commit Message

Mathieu Dubois-Briand Nov. 7, 2026, 1:54 p.m. UTC
Failed copy might still result in a file created, either with a size of
0 or with incomplete data. Make sure to remove this file.

Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
---
 scripts/runqemu | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/scripts/runqemu b/scripts/runqemu
index 6e757d375386..c9f6481cd11e 100755
--- a/scripts/runqemu
+++ b/scripts/runqemu
@@ -1314,12 +1314,12 @@  to your build configuration.
             newrootfs = os.path.join(tmpfsdir, os.path.basename(self.rootfs)) + "." + str(os.getpid())
             logger.info("Copying rootfs to %s" % newrootfs)
             copy_start = time.time()
+            self.cleanup_files.append(newrootfs)
             shutil.copyfile(self.rootfs, newrootfs)
             logger.info("Copy done in %s seconds" % (time.time() - copy_start))
             self.rootfs = newrootfs
             # Don't need a second copy now!
             self.snapshot = False
-            self.cleanup_files.append(newrootfs)
 
         qb_rootfs_opt = self.get('QB_ROOTFS_OPT')
         if qb_rootfs_opt:
@@ -1712,7 +1712,7 @@  to your build configuration.
                 logger.info('Removing %s' % ent)
                 if os.path.isfile(ent):
                     os.remove(ent)
-                else:
+                elif os.path.exists(ent):
                     shutil.rmtree(ent)
 
         # Deliberately ignore the return code of 'tput smam'.