objectstore, move {u,}mount methods to util.mnt
Move the mount and umount helpers to the new mount utility module. No semantic change in the function.
This commit is contained in:
parent
a43ea66be2
commit
2e09e7937c
2 changed files with 36 additions and 35 deletions
|
|
@ -7,6 +7,7 @@ from typing import Optional, Iterator, Set
|
||||||
|
|
||||||
from osbuild.util.types import PathLike
|
from osbuild.util.types import PathLike
|
||||||
from osbuild.util import jsoncomm, rmrf
|
from osbuild.util import jsoncomm, rmrf
|
||||||
|
from osbuild.util.mnt import mount, umount
|
||||||
from . import api
|
from . import api
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -15,41 +16,6 @@ __all__ = [
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def mount(source, target, bind=True, ro=True, private=True, mode="0755"):
|
|
||||||
options = []
|
|
||||||
if ro:
|
|
||||||
options += ["ro"]
|
|
||||||
if mode:
|
|
||||||
options += [mode]
|
|
||||||
|
|
||||||
args = []
|
|
||||||
if bind:
|
|
||||||
args += ["--rbind"]
|
|
||||||
if private:
|
|
||||||
args += ["--make-rprivate"]
|
|
||||||
if options:
|
|
||||||
args += ["-o", ",".join(options)]
|
|
||||||
|
|
||||||
r = subprocess.run(["mount"] + args + [source, target],
|
|
||||||
stderr=subprocess.STDOUT,
|
|
||||||
stdout=subprocess.PIPE,
|
|
||||||
encoding="utf-8",
|
|
||||||
check=False)
|
|
||||||
|
|
||||||
if r.returncode != 0:
|
|
||||||
code = r.returncode
|
|
||||||
msg = r.stdout.strip()
|
|
||||||
raise RuntimeError(f"{msg} (code: {code})")
|
|
||||||
|
|
||||||
|
|
||||||
def umount(target, lazy=False):
|
|
||||||
args = []
|
|
||||||
if lazy:
|
|
||||||
args += ["--lazy"]
|
|
||||||
subprocess.run(["sync", "-f", target], check=True)
|
|
||||||
subprocess.run(["umount", "-R"] + args + [target], check=True)
|
|
||||||
|
|
||||||
|
|
||||||
class Object:
|
class Object:
|
||||||
def __init__(self, store: "ObjectStore"):
|
def __init__(self, store: "ObjectStore"):
|
||||||
self._init = True
|
self._init = True
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,41 @@ import contextlib
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
|
def mount(source, target, bind=True, ro=True, private=True, mode="0755"):
|
||||||
|
options = []
|
||||||
|
if ro:
|
||||||
|
options += ["ro"]
|
||||||
|
if mode:
|
||||||
|
options += [mode]
|
||||||
|
|
||||||
|
args = []
|
||||||
|
if bind:
|
||||||
|
args += ["--rbind"]
|
||||||
|
if private:
|
||||||
|
args += ["--make-rprivate"]
|
||||||
|
if options:
|
||||||
|
args += ["-o", ",".join(options)]
|
||||||
|
|
||||||
|
r = subprocess.run(["mount"] + args + [source, target],
|
||||||
|
stderr=subprocess.STDOUT,
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
encoding="utf-8",
|
||||||
|
check=False)
|
||||||
|
|
||||||
|
if r.returncode != 0:
|
||||||
|
code = r.returncode
|
||||||
|
msg = r.stdout.strip()
|
||||||
|
raise RuntimeError(f"{msg} (code: {code})")
|
||||||
|
|
||||||
|
|
||||||
|
def umount(target, lazy=False):
|
||||||
|
args = []
|
||||||
|
if lazy:
|
||||||
|
args += ["--lazy"]
|
||||||
|
subprocess.run(["sync", "-f", target], check=True)
|
||||||
|
subprocess.run(["umount", "-R"] + args + [target], check=True)
|
||||||
|
|
||||||
|
|
||||||
class MountGuard(contextlib.AbstractContextManager):
|
class MountGuard(contextlib.AbstractContextManager):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.mounts = []
|
self.mounts = []
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue