diff --git a/pmb/install/losetup.py b/pmb/install/losetup.py index ab1ad65f07dababa56e340e033d2bf63d3a83539..6e2b313d9437c807617d1ec24771e317ded51c04 100644 --- a/pmb/install/losetup.py +++ b/pmb/install/losetup.py @@ -13,7 +13,7 @@ import pmb.chroot from pmb.core import Chroot -def init() -> None: +def init(): if not Path("/sys/module/loop").is_dir(): pmb.helpers.run.root(["modprobe", "loop"]) for loopdevice in Path("/dev/").glob("loop*"): @@ -22,7 +22,7 @@ def init() -> None: pmb.helpers.mount.bind_file(loopdevice, Chroot.native() / loopdevice) -def mount(img_path: Path, _sector_size: int | None = None) -> Path: +def mount(img_path: Path, _sector_size: int | None = None): """ :param img_path: Path to the img file inside native chroot. """ @@ -56,8 +56,6 @@ def mount(img_path: Path, _sector_size: int | None = None) -> Path: raise e pass - raise AssertionError("This should never be reached") - def device_by_back_file(back_file: Path) -> Path: """ @@ -77,7 +75,7 @@ def device_by_back_file(back_file: Path) -> Path: raise RuntimeError(f"Failed to find loop device for {back_file}") -def umount(img_path: Path) -> None: +def umount(img_path: Path): """ :param img_path: Path to the img file inside native chroot. """ @@ -90,17 +88,18 @@ def umount(img_path: Path) -> None: pmb.chroot.root(["losetup", "-d", device]) -def detach_all() -> None: +def detach_all(): """ Detach all loop devices used by pmbootstrap """ - losetup_output = pmb.chroot.root(["losetup", "--json", "--list"], output_return=True) + losetup_output = pmb.helpers.run.root(["losetup", "--json", "--list"], output_return=True) if not losetup_output: return losetup = json.loads(losetup_output) work = get_context().config.work for loopdevice in losetup["loopdevices"]: + print(loopdevice["back-file"]) if Path(loopdevice["back-file"]).is_relative_to(work): - pmb.chroot.root(["kpartx", "-d", loopdevice["name"]], check=False) - pmb.chroot.root(["losetup", "-d", loopdevice["name"]]) + pmb.helpers.run.root(["kpartx", "-d", loopdevice["name"]], check=False) + pmb.helpers.run.root(["losetup", "-d", loopdevice["name"]]) return