Skip to content

Commit

Permalink
partitioning: Handle exceptions differently for getDevice() and Disk()
Browse files Browse the repository at this point in the history
This commit fixes a really bad bug.

If parted.getDevice() throws an exception:

- There's no need to format the device, we're dealing with something
which can't be read at device level here, not at partition table or
partition level.
- The disk_device variable is either NULL or worse, it still has
the value of the previous device. If the user answers YES to format the
device, it formats the previous one.

This bug is introduced by ad29db2 and
present in the LMDE 6 BETA.
  • Loading branch information
clefebvre committed Sep 19, 2023
1 parent a8128a8 commit 9a718e3
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions usr/lib/live-installer/partitioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,6 @@ def get_disks():
if re.match("/dev/mmcblk[0-9]+rpmb$", device):
print("Excluding %s (eMMC hardware device)" % device)
continue
# Exclude empty devices (for instance: a card reader with no card in it)
if size[:-1] == "0":
print("Excluding %s (device's size is 0)" % device)
continue

# Convert size to manufacturer's size (i.e. GB, not GiB)
unit_index = 'BKMGTPEZY'.index(size.upper()[-1])
Expand Down Expand Up @@ -266,10 +262,16 @@ def __init__(self):
print('Disks: ', self.disks)
already_done_full_disk_format = False
for disk_path, disk_description in self.disks:
# Get the device from parted
try:
print(" Analyzing path='%s' description='%s'" % (disk_path, disk_description))
disk_device = parted.getDevice(disk_path)
print(" - Found the device...")
except Exception as detail:
print(" - Found an issue while looking for the device: %s" % detail)
continue
# Get the partitions from parted
try:
disk = parted.Disk(disk_device)
print(" - Found the disk...")
except Exception as detail:
Expand Down

0 comments on commit 9a718e3

Please sign in to comment.