]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
sandbox: Bind mount on top of symlink if possible
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 29 Nov 2024 13:37:29 +0000 (14:37 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 29 Nov 2024 17:43:14 +0000 (18:43 +0100)
Instead of mounting on top of the resolved symlink, let's just mount
directly on top of the symlink if we can.

Fixes #3247

mkosi/sandbox.py

index 20fca27aae9a6fd8a21e0439836c5ae8171db6a0..be1a0370f95aba307e0afe4090c6dc58d1e87fed 100755 (executable)
@@ -459,11 +459,17 @@ class BindOperation(FSOperation):
 
     def execute(self, oldroot: str, newroot: str) -> None:
         src = chase(oldroot, self.src)
-        dst = chase(newroot, self.dst)
 
         if not os.path.exists(src) and not self.required:
             return
 
+        # If we're mounting a file on top of a symlink, mount directly on top of the symlink instead of
+        # resolving it.
+        dst = joinpath(newroot, self.dst)
+        if not os.path.isdir(src) and os.path.islink(dst):
+            return mount_rbind(src, dst, attrs=MOUNT_ATTR_RDONLY if self.readonly else 0)
+
+        dst = chase(newroot, self.dst)
         if not os.path.exists(dst):
             isfile = os.path.isfile(src)