From: Daan De Meyer Date: Sat, 15 Feb 2025 21:58:04 +0000 (+0100) Subject: Make sure we always delete workspace / "root" as a subvolume X-Git-Tag: v26~379^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c71c7d933bbad8851a80d1db83ddc1d8a8b362e1;p=thirdparty%2Fmkosi.git Make sure we always delete workspace / "root" as a subvolume Currently, we delete it as a subvolume if the build succeeds but not if the build fails. Let's handle the deletion in setup_workspace() so we delete it as a subvolume both on success and on failure. --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 0828c87cd..9a6f221ea 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -3770,7 +3770,9 @@ def setup_workspace(args: Args, config: Config) -> Iterator[Path]: workspace = Path(tempfile.mkdtemp(dir=config.workspace_dir_or_default(), prefix="mkosi-workspace-")) # Discard setuid/setgid bits as these are inherited and can leak into the image. workspace.chmod(stat.S_IMODE(workspace.stat().st_mode) & ~(stat.S_ISGID | stat.S_ISUID)) - stack.callback(lambda: rmtree(workspace, sandbox=config.sandbox)) + # Explicitly pass the "root" subdirectory first because on btrfs it's likely a subvolume and this + # allows us to delete it with btrfs subvolume delete instead of a costly rm -rf. + stack.callback(lambda: rmtree(workspace / "root", workspace, sandbox=config.sandbox)) (workspace / "tmp").mkdir(mode=0o1777) with scopedenv({"TMPDIR": os.fspath(workspace / "tmp")}): @@ -4016,9 +4018,6 @@ def build_image(context: Context) -> None: run_postoutput_scripts(context) finalize_staging(context) - if not context.args.debug_workspace: - rmtree(context.root, sandbox=context.sandbox) - print_output_size(context.config.output_dir_or_cwd() / context.config.output_with_compression)