From: Daan De Meyer Date: Sat, 22 Mar 2025 10:51:36 +0000 (+0100) Subject: user: Make INVOKING_USER.runtime_dir() return the user runtime dir X-Git-Tag: v26~305^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fa986e4a74c751f33b4e043d5b17b5972d0cfb49;p=thirdparty%2Fmkosi.git user: Make INVOKING_USER.runtime_dir() return the user runtime dir Let's not return the mkosi specific directory, but the wider runtime directory. --- diff --git a/mkosi/qemu.py b/mkosi/qemu.py index b9605286f..8e6ec7770 100644 --- a/mkosi/qemu.py +++ b/mkosi/qemu.py @@ -828,10 +828,11 @@ def finalize_initrd(config: Config) -> Iterator[Optional[Path]]: @contextlib.contextmanager def finalize_state(config: Config, cid: int) -> Iterator[None]: - (INVOKING_USER.runtime_dir() / "machine").mkdir(parents=True, exist_ok=True) + statedir = INVOKING_USER.runtime_dir() / "mkosi/machine" + statedir.mkdir(parents=True, exist_ok=True) - with flock(INVOKING_USER.runtime_dir() / "machine"): - if (p := INVOKING_USER.runtime_dir() / "machine" / f"{config.machine_or_name()}.json").exists(): + with flock(statedir): + if (p := statedir / f"{config.machine_or_name()}.json").exists(): die( f"Another virtual machine named {config.machine_or_name()} is already running", hint="Use --machine to specify a different virtual machine name", @@ -851,7 +852,7 @@ def finalize_state(config: Config, cid: int) -> Iterator[None]: try: yield finally: - with flock(INVOKING_USER.runtime_dir() / "machine"): + with flock(statedir): p.unlink(missing_ok=True) @@ -1611,8 +1612,9 @@ def run_qemu(args: Args, config: Config) -> None: def run_ssh(args: Args, config: Config) -> None: - with flock(INVOKING_USER.runtime_dir() / "machine"): - if not (p := INVOKING_USER.runtime_dir() / "machine" / f"{config.machine_or_name()}.json").exists(): + statedir = INVOKING_USER.runtime_dir() / "mkosi/machine" + with flock(statedir): + if not (p := statedir / f"{config.machine_or_name()}.json").exists(): die( f"{p} not found, cannot SSH into virtual machine {config.machine_or_name()}", hint="Is the machine running and was it built with Ssh=yes and Vsock=yes?", diff --git a/mkosi/user.py b/mkosi/user.py index d83d1dd3c..e50f5118c 100644 --- a/mkosi/user.py +++ b/mkosi/user.py @@ -66,7 +66,7 @@ class INVOKING_USER: else: d = Path("/run") - return d / "mkosi" + return d @classmethod def chown(cls, path: Path) -> None: