Skip to content

Commit 66121e1

Browse files
committed
diskutil: Fix addPartition()
Signed-off-by: Hector Martin <[email protected]>
1 parent 8641e3c commit 66121e1

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

src/diskutil.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,18 +144,23 @@ def addVolume(self, container, name, **kwargs):
144144
self.action("quiet", "apfs", "addVolume", container, "apfs", name, *args, verbose=True)
145145

146146
def addPartition(self, after, fs, label, size):
147+
size = str(size)
147148
self.action("quiet", "addPartition", after, fs, label, size, verbose=True)
149+
148150
disk = after.rsplit("s", 1)[0]
151+
149152
self.get_list()
150-
for i, p in enumerate(self.disk_parts[disk]["Partitions"]):
151-
if after == p["DeviceIdentifier"]:
152-
break
153-
else:
154-
raise Exception("Could not find new partition")
153+
parts = self.get_partitions(disk)
154+
155+
for i, part in enumerate(parts):
156+
logging.info(f"Checking #{i} {part.name}...")
157+
if part.name == after:
158+
logging.info(f"Found previous partition {part.name}...")
159+
new_part = self.get_partition_info(parts[i + 1].name, refresh_apfs=(fs == "apfs"))
160+
logging.info(f"New partition: {new_part!r}")
161+
return new_part
155162

156-
new = self.disk_parts[disk]["Partitions"][i + 1]
157-
return self.get_partition_info(new["DeviceIdentifier"],
158-
refresh_apfs=(fs == "apfs"))
163+
raise Exception("Could not find new partition")
159164

160165
def changeVolumeRole(self, volume, role):
161166
self.action("quiet", "apfs", "changeVolumeRole", volume, role, verbose=True)

0 commit comments

Comments
 (0)