forked from Mirror/pmbootstrap
install: losetup: add detach_all() (MR 2252)
Add a function that just detaches all loop devices that are backed by a file inside the pmbootstrap work dir. Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
This commit is contained in:
parent
c4b4c41b8d
commit
c061ef8123
1 changed files with 17 additions and 0 deletions
|
@ -3,6 +3,7 @@
|
||||||
import json
|
import json
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List
|
from typing import List
|
||||||
|
from pmb.core.context import get_context
|
||||||
from pmb.helpers import logging
|
from pmb.helpers import logging
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
@ -85,3 +86,19 @@ def umount(img_path: Path):
|
||||||
return
|
return
|
||||||
logging.debug(f"(native) umount {device}")
|
logging.debug(f"(native) umount {device}")
|
||||||
pmb.chroot.root(["losetup", "-d", device])
|
pmb.chroot.root(["losetup", "-d", device])
|
||||||
|
|
||||||
|
def detach_all():
|
||||||
|
"""
|
||||||
|
Detach all loop devices used by pmbootstrap
|
||||||
|
"""
|
||||||
|
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(["losetup", "-d", loopdevice["name"]])
|
||||||
|
return
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue