Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib/disk.py
diff options
context:
space:
mode:
Diffstat (limited to 'archinstall/lib/disk.py')
-rw-r--r--archinstall/lib/disk.py29
1 files changed, 20 insertions, 9 deletions
diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py
index f8703ae3..44f2742b 100644
--- a/archinstall/lib/disk.py
+++ b/archinstall/lib/disk.py
@@ -1,6 +1,7 @@
import glob
import pathlib
import re
+import time
from collections import OrderedDict
from typing import Optional
@@ -77,7 +78,7 @@ class BlockDevice:
raise DiskError(f'Could not locate backplane info for "{self.path}"')
if self.info['type'] == 'loop':
- for drive in json.loads(b''.join(SysCommand(['losetup', '--json'], hide_from_log=True)).decode('UTF_8'))['loopdevices']:
+ for drive in json.loads(b''.join(SysCommand(['losetup', '--json'])).decode('UTF_8'))['loopdevices']:
if not drive['name'] == self.path:
continue
@@ -264,7 +265,9 @@ class Partition:
raise DiskError(f'Could not mount and check for content on {self.path} because: {b"".join(handle)}')
files = len(glob.glob(f"{temporary_mountpoint}/*"))
- SysCommand(f'/usr/bin/umount {temporary_mountpoint}')
+ iterations = 0
+ while SysCommand(f"/usr/bin/umount -R {temporary_mountpoint}").exit_code != 0 and (iterations := iterations+1) < 10:
+ time.sleep(1)
temporary_path.rmdir()
@@ -425,7 +428,7 @@ class Partition:
"""
try:
self.format(self.filesystem, '/dev/null', log_formatting=False, allow_formatting=True)
- except SysCallError:
+ except (SysCallError, DiskError):
pass # We supported it, but /dev/null is not formatable as expected so the mkfs call exited with an error code
except UnknownFilesystemFormat as err:
raise err
@@ -572,7 +575,7 @@ def all_disks(*args, **kwargs):
kwargs.setdefault("partitions", False)
drives = OrderedDict()
# for drive in json.loads(sys_command(f'losetup --json', *args, **lkwargs, hide_from_log=True)).decode('UTF_8')['loopdevices']:
- for drive in json.loads(b''.join(SysCommand('lsblk --json -l -n -o path,size,type,mountpoint,label,pkname,model', *args, **kwargs, hide_from_log=True)).decode('UTF_8'))['blockdevices']:
+ for drive in json.loads(b''.join(SysCommand('lsblk --json -l -n -o path,size,type,mountpoint,label,pkname,model')).decode('UTF_8'))['blockdevices']:
if not kwargs['partitions'] and drive['type'] == 'part':
continue
@@ -603,13 +606,17 @@ def harddrive(size=None, model=None, fuzzy=False):
return collection[drive]
-def get_mount_info(path):
+def get_mount_info(path) -> dict:
try:
- output = b''.join(SysCommand(f'/usr/bin/findmnt --json {path}'))
+ output = SysCommand(f'/usr/bin/findmnt --json {path}')
except SysCallError:
return {}
output = output.decode('UTF-8')
+
+ if not output:
+ return {}
+
output = json.loads(output)
if 'filesystems' in output:
if len(output['filesystems']) > 1:
@@ -618,15 +625,19 @@ def get_mount_info(path):
return output['filesystems'][0]
-def get_partitions_in_use(mountpoint):
+def get_partitions_in_use(mountpoint) -> list:
try:
- output = b''.join(SysCommand(f'/usr/bin/findmnt --json -R {mountpoint}'))
+ output = SysCommand(f'/usr/bin/findmnt --json -R {mountpoint}')
except SysCallError:
- return {}
+ return []
mounts = []
output = output.decode('UTF-8')
+
+ if not output:
+ return []
+
output = json.loads(output)
for target in output.get('filesystems', []):
mounts.append(Partition(target['source'], None, filesystem=target.get('fstype', None), mountpoint=target['target']))