]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Fix /var/tmp directory cleanup
authorDaanDeMeyer <daan.j.demeyer@gmail.com>
Thu, 3 Jul 2025 11:45:22 +0000 (13:45 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Thu, 3 Jul 2025 16:05:53 +0000 (17:05 +0100)
Currently, if /work does not exist, we go into the exception handler which
doesn't do anything if the errno is ENOENT, even though we still need to
remove the parent directory.

mkosi/run.py

index 97c685ad88a1e1102bb9a2683ebff335a2f5bd97..d41cc5ed0be12f36058ce6b82ee07f489659d7c2 100644 (file)
@@ -444,7 +444,8 @@ def vartmpdir() -> Iterator[Path]:
         # the subdirectory when it is empty is not a problem because deleting a subdirectory depends on the
         # permissions of the parent directory and not the directory itself.
         try:
-            (d / "work").rmdir()
+            if (p := d / "work").exists():
+                p.rmdir()
         except OSError as e:
             if e.errno == errno.ENOTEMPTY:
 
@@ -453,7 +454,7 @@ def vartmpdir() -> Iterator[Path]:
                     shutil.rmtree(d)
 
                 fork_and_wait(remove)
-            elif e.errno != errno.ENOENT:
+            else:
                 raise
         else:
             shutil.rmtree(d)