]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
user: Make INVOKING_USER.runtime_dir() return the user runtime dir
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Sat, 22 Mar 2025 10:51:36 +0000 (11:51 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 24 Mar 2025 09:43:44 +0000 (10:43 +0100)
Let's not return the mkosi specific directory, but the wider runtime
directory.

mkosi/qemu.py
mkosi/user.py

index b9605286f21f83d01d31f7c6b2975863d15ba64b..8e6ec7770c065c12123ce27020f53a1d90efe7ba 100644 (file)
@@ -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?",
index d83d1dd3cd4148ac930dd31694527a494957d431..e50f5118c0de25187b3695a6b670993430e8c8c2 100644 (file)
@@ -66,7 +66,7 @@ class INVOKING_USER:
         else:
             d = Path("/run")
 
-        return d / "mkosi"
+        return d
 
     @classmethod
     def chown(cls, path: Path) -> None: