From: Daan De Meyer Date: Tue, 26 Nov 2024 14:48:38 +0000 (+0100) Subject: Rework default initrd cleanup X-Git-Tag: v25~142^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e3d80a7a326968551e68047660740f1b91cc465d;p=thirdparty%2Fmkosi.git Rework default initrd cleanup 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 --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 2ed312ff5..705ab6974 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -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):