Refactor umount() (#2516)
This commit is contained in:
parent
63cfee434e
commit
cee32670f3
|
|
@ -695,28 +695,21 @@ class DeviceHandler(object):
|
||||||
raise DiskError(f'Could not mount {dev_path}: {command}\n{err.message}')
|
raise DiskError(f'Could not mount {dev_path}: {command}\n{err.message}')
|
||||||
|
|
||||||
def umount(self, mountpoint: Path, recursive: bool = False):
|
def umount(self, mountpoint: Path, recursive: bool = False):
|
||||||
try:
|
|
||||||
lsblk_info = get_lsblk_info(mountpoint)
|
lsblk_info = get_lsblk_info(mountpoint)
|
||||||
except SysCallError as ex:
|
|
||||||
# this could happen if before partitioning the device contained 3 partitions
|
|
||||||
# and after partitioning only 2 partitions were created, then the modifications object
|
|
||||||
# will have a reference to /dev/sX3 which is being tried to umount here now
|
|
||||||
if 'not a block device' in ex.message:
|
|
||||||
return
|
|
||||||
raise ex
|
|
||||||
|
|
||||||
if len(lsblk_info.mountpoints) > 0:
|
if not lsblk_info.mountpoints:
|
||||||
|
return
|
||||||
|
|
||||||
debug(f'Partition {mountpoint} is currently mounted at: {[str(m) for m in lsblk_info.mountpoints]}')
|
debug(f'Partition {mountpoint} is currently mounted at: {[str(m) for m in lsblk_info.mountpoints]}')
|
||||||
|
|
||||||
for mountpoint in lsblk_info.mountpoints:
|
cmd = ['umount']
|
||||||
debug(f'Unmounting mountpoint: {mountpoint}')
|
|
||||||
|
|
||||||
command = 'umount'
|
|
||||||
|
|
||||||
if recursive:
|
if recursive:
|
||||||
command += ' -R'
|
cmd.append('-R')
|
||||||
|
|
||||||
SysCommand(f'{command} {mountpoint}')
|
for path in lsblk_info.mountpoints:
|
||||||
|
debug(f'Unmounting mountpoint: {path}')
|
||||||
|
SysCommand(cmd + [str(path)])
|
||||||
|
|
||||||
def detect_pre_mounted_mods(self, base_mountpoint: Path) -> List[DeviceModification]:
|
def detect_pre_mounted_mods(self, base_mountpoint: Path) -> List[DeviceModification]:
|
||||||
part_mods: Dict[Path, List[PartitionModification]] = {}
|
part_mods: Dict[Path, List[PartitionModification]] = {}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue