Skip to content

Commit

Permalink
boot_control.common: add a plain version of mount
Browse files Browse the repository at this point in the history
  • Loading branch information
Bodong-Yang committed Jun 19, 2024
1 parent 14caa8a commit b149289
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/otaclient/app/boot_control/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
subprocess_check_output,
write_str_to_file_sync,
)
from otaclient_common.typing import StrOrPath

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -234,6 +235,36 @@ def set_ext4_fslabel(cls, dev: str, fslabel: str, *, raise_exception: bool = Tru
cmd = ["e2label", dev, fslabel]
subprocess_call(cmd, raise_exception=raise_exception)

@classmethod
def mount(
cls,
target: StrOrPath,
mount_point: StrOrPath,
*,
options: list[str] | None = None,
params: list[str] | None = None,
raise_exception: bool = True,
) -> None:
"""Thin wrapper to call mount using subprocess.
This will call the following:
mount [-o <option1>,[<option2>[,...]] [<param1> [<param2>[...]]] <target> <mount_point>
Args:
target (StrOrPath): The target device to mount.
mount_point (StrOrPath): The mount point to mount to.
options (list[str] | None, optional): A list of options, append after -o. Defaults to None.
params (list[str] | None, optional): A list of params. Defaults to None.
raise_exception (bool, optional): Whether to raise exception on failed call. Defaults to True.
"""
cmd = ["mount"]
if options:
cmd.extend(["-o", ",".join(options)])
if params:
cmd.extend(params)
cmd = [*cmd, str(target), str(mount_point)]
subprocess_call(cmd, raise_exception=raise_exception)

@classmethod
def mount_rw(
cls, target: str, mount_point: Path | str, *, raise_exception: bool = True
Expand Down

0 comments on commit b149289

Please sign in to comment.