On Mon, 2014-12-01 at 09:29 -0600, David Lehman wrote:
On 11/26/2014 07:37 AM, Vratislav Podzimek wrote:
Adding a new partition may change partitions' order (e.g. adding sda1 after sda2) so we need to handle that correctly.
Signed-off-by: Vratislav Podzimek vpodzime@redhat.com
blivet/devicetree.py | 9 +++++++++ blivet/formats/disklabel.py | 26 ++++++++++++++++++++++++-- python-blivet.spec | 2 +- 3 files changed, 34 insertions(+), 3 deletions(-)
diff --git a/blivet/devicetree.py b/blivet/devicetree.py index f6cf600..98b1251 100644 --- a/blivet/devicetree.py +++ b/blivet/devicetree.py @@ -26,6 +26,7 @@ import re import shutil import pprint import copy +import itertools
from .errors import CryptoError, DeviceError, DeviceTreeError, DiskLabelCommitError, DMError, FSError, InvalidDiskLabelError, LUKSError, MDRaidError, StorageError from .devices import BTRFSDevice, BTRFSSubVolumeDevice, BTRFSVolumeDevice, BTRFSSnapShotDevice @@ -402,6 +403,14 @@ class DeviceTree(object): newdev.addHook(new=new) self._devices.append(newdev)
# adding a partition may change partedPartition's paths which are used
# to construct names which thus should be updated
if isinstance(newdev, PartitionDevice):
sibling_parts_lists = [self.getChildren(parent) for parent in newdev.parents]
sibling_parts = itertools.chain(*sibling_parts_lists)
for part in sibling_parts:
part.updateName()
# don't include "req%d" partition names if ((newdev.type != "partition" or not newdev.name.startswith("req")) and
It would be much better to just sort them however you need them here instead of changing the return value of getChildren for all callers.
Discussed on IRC that this is hardly possbile because there is no list of children of each device. The list returned by getChildren is constructed ad-hoc by going through all devices and checking their 'parents' references.