Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib/disk/device_model.py
diff options
context:
space:
mode:
authorcodefiles <11915375+codefiles@users.noreply.github.com>2024-03-12 05:25:15 -0400
committerGitHub <noreply@github.com>2024-03-12 10:25:15 +0100
commitdf2884085dc06f71f2bb201a316828c23b6299dd (patch)
tree52a2b94f506aa9e1f8b47b75d276f006af9e53d7 /archinstall/lib/disk/device_model.py
parent613bec6562c4d67c4c93d443e6d7e93fdb41ba66 (diff)
Add udev sync before lsblk that follows formatting (#2412)
Diffstat (limited to 'archinstall/lib/disk/device_model.py')
-rw-r--r--archinstall/lib/disk/device_model.py42
1 files changed, 18 insertions, 24 deletions
diff --git a/archinstall/lib/disk/device_model.py b/archinstall/lib/disk/device_model.py
index 423c65e4..fe96203c 100644
--- a/archinstall/lib/disk/device_model.py
+++ b/archinstall/lib/disk/device_model.py
@@ -3,7 +3,6 @@ from __future__ import annotations
import dataclasses
import json
import math
-import time
import uuid
from dataclasses import dataclass, field
from enum import Enum
@@ -1103,39 +1102,34 @@ def _clean_field(name: str, clean_type: CleanType) -> str:
return name.replace('_percentage', '%').replace('_', '-')
-def _fetch_lsblk_info(dev_path: Optional[Union[Path, str]] = None, retry: int = 3) -> List[LsblkInfo]:
+def _fetch_lsblk_info(dev_path: Optional[Union[Path, str]] = None) -> List[LsblkInfo]:
fields = [_clean_field(f, CleanType.Lsblk) for f in LsblkInfo.fields()]
- lsblk_fields = ','.join(fields)
-
- if not dev_path:
- dev_path = ''
-
- for retry_attempt in range(retry + 1):
- try:
- result = SysCommand(f'lsblk --json -b -o+{lsblk_fields} {dev_path}').decode()
- break
- except SysCallError as err:
- # Get the output minus the message/info from lsblk if it returns a non-zero exit code.
- if err.worker:
- err_str = err.worker.decode()
- debug(f'Error calling lsblk: {err_str}')
- else:
- raise err
+ cmd = ['lsblk', '--json', '--bytes', '--output', '+' + ','.join(fields)]
+
+ if dev_path:
+ cmd.append(str(dev_path))
- if retry_attempt == retry:
- raise err
+ try:
+ result = SysCommand(cmd).decode()
+ except SysCallError as err:
+ # Get the output minus the message/info from lsblk if it returns a non-zero exit code.
+ if err.worker:
+ err_str = err.worker.decode()
+ debug(f'Error calling lsblk: {err_str}')
- time.sleep(1)
+ if dev_path:
+ raise DiskError(f'Failed to read disk "{dev_path}" with lsblk')
+
+ raise err
try:
block_devices = json.loads(result)
- blockdevices = block_devices['blockdevices']
- return [LsblkInfo.from_json(device) for device in blockdevices]
except json.decoder.JSONDecodeError as err:
error(f"Could not decode lsblk JSON: {result}")
raise err
- raise DiskError(f'Failed to read disk "{dev_path}" with lsblk')
+ blockdevices = block_devices['blockdevices']
+ return [LsblkInfo.from_json(device) for device in blockdevices]
def get_lsblk_info(dev_path: Union[Path, str]) -> LsblkInfo: