]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Take shared lock in copy_ephemeral()
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 10 Apr 2025 19:30:25 +0000 (21:30 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 10 Apr 2025 20:04:09 +0000 (22:04 +0200)
We don't need an exclusive lock to make this copy, so let's take only
a shared lock.

mkosi/qemu.py
mkosi/util.py

index f138eca8ae04a2b2d90df76e8e837bf7a9a3cf26..3961bc849461ba5cb2d5285c0c6ef3259858cb58 100644 (file)
@@ -615,7 +615,7 @@ def copy_ephemeral(config: Config, src: Path) -> Iterator[Path]:
                 sandbox=config.sandbox,
             )
 
-        with flock(src):
+        with flock(src, flags=fcntl.LOCK_SH):
             fork_and_wait(copy)
         yield tmp
     finally:
index fe8c8006ef62b797a4e52c28cb8e9a3c81f0da48..81710924f0632411f6ff7150afdfea230821b3d2 100644 (file)
@@ -139,9 +139,9 @@ def flock(path: Path, flags: int = fcntl.LOCK_EX) -> Iterator[int]:
 
 
 @contextlib.contextmanager
-def flock_or_die(path: Path) -> Iterator[Path]:
+def flock_or_die(path: Path, flags: int = fcntl.LOCK_EX) -> Iterator[Path]:
     try:
-        with flock(path, fcntl.LOCK_EX | fcntl.LOCK_NB):
+        with flock(path, flags | fcntl.LOCK_NB):
             yield path
     except OSError as e:
         if e.errno != errno.EWOULDBLOCK: