]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Rework default initrd cleanup
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 26 Nov 2024 14:48:38 +0000 (15:48 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 26 Nov 2024 14:50:06 +0000 (15:50 +0100)
Currently we only remove the default initrd image cache if the
main image cache is out-of-date and not if the initrd cache is
out-of-date.

Let's fix the problem by calling run_clean() separately on the default
initrd.

Fixes #3231

mkosi/__init__.py

index 2ed312ff5e146acee3490980c54aad32a49f4a9f..705ab6974d52f5d8ca2d8d9bb548f64a49081239 100644 (file)
@@ -4288,7 +4288,7 @@ def needs_build(args: Args, config: Config, force: int = 1) -> bool:
     )
 
 
-def run_clean(args: Args, config: Config, *, resources: Path) -> None:
+def run_clean(args: Args, config: Config) -> None:
     # We remove any cached images if either the user used --force twice, or he/she called "clean"
     # with it passed once. Let's also remove the downloaded package cache if the user specified one
     # additional "--force".
@@ -4347,16 +4347,10 @@ def run_clean(args: Args, config: Config, *, resources: Path) -> None:
     if remove_image_cache and config.cache_dir:
         metadata = [metadata_cache(config)] if not config.image else []
 
-        initrd = (
-            cache_tree_paths(finalize_default_initrd(config, tools=False, resources=resources))
-            if config.distribution != Distribution.custom
-            else []
-        )
-
-        if any(p.exists() for p in itertools.chain(cache_tree_paths(config), initrd, metadata)):
+        if any(p.exists() for p in itertools.chain(cache_tree_paths(config), metadata)):
             with complete_step(f"Removing cache entries of {config.name()} image…"):
                 rmtree(
-                    *(p for p in itertools.chain(cache_tree_paths(config), initrd, metadata) if p.exists()),
+                    *(p for p in itertools.chain(cache_tree_paths(config), metadata) if p.exists()),
                     sandbox=sandbox,
                 )
 
@@ -4606,10 +4600,13 @@ def run_verb(args: Args, images: Sequence[Config], *, resources: Path) -> None:
 
     if args.verb == Verb.clean:
         if tools:
-            run_clean(args, tools, resources=resources)
+            run_clean(args, tools)
 
         for config in images:
-            run_clean(args, config, resources=resources)
+            run_clean(args, config)
+
+        if last.output_format != OutputFormat.none:
+            run_clean(args, finalize_default_initrd(last, tools=False, resources=resources))
 
         rmtree(Path(".mkosi-private"))
 
@@ -4681,13 +4678,16 @@ def run_verb(args: Args, images: Sequence[Config], *, resources: Path) -> None:
                 hint="Build once with -i yes to update the tools tree",
             )
 
-        run_clean(args, tools, resources=resources)
+        run_clean(args, tools)
 
     # First, process all directory removals because otherwise if different images share directories
     # a later image build could end up deleting the output generated by an earlier image build.
     if args.verb.needs_build() and (needs_build(args, last) or args.wipe_build_dir):
         for config in images:
-            run_clean(args, config, resources=resources)
+            run_clean(args, config)
+
+        if last.output_format != OutputFormat.none:
+            run_clean(args, finalize_default_initrd(last, tools=False, resources=resources))
 
     if tools and not (tools.output_dir_or_cwd() / tools.output).exists():
         with prepend_to_environ_path(tools):