From 9258bda89d53b9a3ba01edb66ac27d6239a33f46 Mon Sep 17 00:00:00 2001 From: Gianluca Zuccarelli Date: Fri, 8 Mar 2024 14:04:00 +0000 Subject: [PATCH] util/mnt: add a remount paramater This is just a temporary workaround to get the containers-storage input working in `bootc-image-builder` --- osbuild/util/mnt.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/osbuild/util/mnt.py b/osbuild/util/mnt.py index 41231e1a..9a50deb6 100644 --- a/osbuild/util/mnt.py +++ b/osbuild/util/mnt.py @@ -50,11 +50,22 @@ def umount(target, lazy=False): class MountGuard(contextlib.AbstractContextManager): def __init__(self): self.mounts = [] + self.remount = False - def mount(self, source, target, bind=True, permissions: Optional[MountPermissions] = None, mode="0755"): + def mount( + self, + source, + target, + bind=True, + remount=False, + permissions: Optional[MountPermissions] = None, + mode="0755"): + self.remount = remount options = [] if bind: options += ["bind"] + if remount: + options += ["remount"] if permissions: if permissions not in list(MountPermissions): raise ValueError(f"unknown filesystem permissions: {permissions}") @@ -86,8 +97,9 @@ class MountGuard(contextlib.AbstractContextManager): # The sync should in theory not be needed but in rare # cases `target is busy` error has been spotted. # Calling `sync` does not hurt so we keep it for now. - subprocess.run(["sync", "-f", target], check=True) - subprocess.run(["umount", target], check=True) + if not self.remount: + subprocess.run(["sync", "-f", target], check=True) + subprocess.run(["umount", target], check=True) def __exit__(self, exc_type, exc_val, exc_tb): self.umount()