Skip to content

Commit

Permalink
cmdhelper: aligns all mount related methods signature
Browse files Browse the repository at this point in the history
  • Loading branch information
Bodong-Yang committed Nov 26, 2024
1 parent 70eb5b3 commit 405558f
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/otaclient_common/cmdhelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ def __call__(
mount_point: StrOrPath,
*,
raise_exception: bool = True,
**kwargs,
) -> None: ...


Expand Down Expand Up @@ -367,7 +366,7 @@ def mount(


def mount_rw(
target: str, mount_point: StrOrPath, *, raise_exception: bool = True
target: StrOrPath, mount_point: StrOrPath, *, raise_exception: bool = True
) -> None: # pragma: no cover
"""Mount the <target> to <mount_point> read-write.
Expand All @@ -378,7 +377,7 @@ def mount_rw(
mount events propagation to/from this mount point.
Args:
target (str): target to be mounted.
target (StrOrPath): target to be mounted.
mount_point (StrOrPath): mount point to mount to.
raise_exception (bool, optional): raise exception on subprocess call failed.
Defaults to True.
Expand All @@ -388,23 +387,23 @@ def mount_rw(
"mount",
"-o", "rw",
"--make-private", "--make-unbindable",
target,
str(target),
str(mount_point),
]
# fmt: on
subprocess_call(cmd, raise_exception=raise_exception)


def bind_mount_ro(
target: str, mount_point: StrOrPath, *, raise_exception: bool = True
target: StrOrPath, mount_point: StrOrPath, *, raise_exception: bool = True
) -> None: # pragma: no cover
"""Bind mount the <target> to <mount_point> read-only.
This is implemented by calling:
mount -o bind,ro --make-private --make-unbindable <target> <mount_point>
Args:
target (str): target to be mounted.
target (StrOrPath): target to be mounted.
mount_point (StrOrPath): mount point to mount to.
raise_exception (bool, optional): raise exception on subprocess call failed.
Defaults to True.
Expand All @@ -414,30 +413,32 @@ def bind_mount_ro(
"mount",
"-o", "bind,ro",
"--make-private", "--make-unbindable",
target,
str(target),
str(mount_point)
]
# fmt: on
subprocess_call(cmd, raise_exception=raise_exception)


def mount_ro(
target: str, mount_point: StrOrPath, *, raise_exception: bool = True
target: StrOrPath, mount_point: StrOrPath, *, raise_exception: bool = True
) -> None: # pragma: no cover
"""Mount <target> to <mount_point> read-only.
If the target device is mounted, we bind mount the target device to mount_point.
if the target device is not mounted, we directly mount it to the mount_point.
Args:
target (str): target to be mounted.
target (StrOrPath): target to be mounted.
mount_point (StrOrPath): mount point to mount to.
raise_exception (bool, optional): raise exception on subprocess call failed.
Defaults to True.
"""
# NOTE: set raise_exception to false to allow not mounted
# not mounted dev will have empty return str
if _active_mount_point := get_mount_point_by_dev(target, raise_exception=False):
if _active_mount_point := get_mount_point_by_dev(
str(target), raise_exception=False
):
bind_mount_ro(
_active_mount_point,
mount_point,
Expand All @@ -450,7 +451,7 @@ def mount_ro(
"mount",
"-o", "ro",
"--make-private", "--make-unbindable",
target,
str(target),
str(mount_point),
]
# fmt: on
Expand Down

0 comments on commit 405558f

Please sign in to comment.