[PATCH 1/2] Return device's children sorted by name

Vratislav Podzimek vpodzime at redhat.com
Thu Dec 4 08:53:39 UTC 2014


On Mon, 2014-12-01 at 08:29 -0500, Anne Mulhern wrote:
> 
> 
> 
> ----- Original Message -----
> > From: "Vratislav Podzimek" <vpodzime at redhat.com>
> > To: anaconda-patches at lists.fedorahosted.org
> > Sent: Wednesday, November 26, 2014 8:37:31 AM
> > Subject: [PATCH 1/2] Return device's children sorted by name
> > 
> > No code should rely on children order, but the list is sometimes transformed
> > into something visual seen by users.
> > 
> > Related: rhbz#1166598
> > Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
> > ---
> >  blivet/devicetree.py | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/blivet/devicetree.py b/blivet/devicetree.py
> > index 1a7b144..f6cf600 100644
> > --- a/blivet/devicetree.py
> > +++ b/blivet/devicetree.py
> > @@ -2483,7 +2483,7 @@ class DeviceTree(object):
> >  
> >      def getChildren(self, device):
> >          """ Return a list of a device's children. """
> > -        return [c for c in self._devices if device in c.parents]
> > +        return sorted((c for c in self._devices if device in c.parents),
> > key=lambda c:c.name)
> >  
> >      def resolveDevice(self, devspec, blkidTab=None, cryptTab=None,
> >      options=None):
> >          """ Return the device matching the provided device specification.
> > --
> > 1.9.3
> > 
> > _______________________________________________
> > anaconda-patches mailing list
> > anaconda-patches at lists.fedorahosted.org
> > https://lists.fedorahosted.org/mailman/listinfo/anaconda-patches
> > 
> 
> There seems to be no reason for this patch.
> 
> Client code can sort the children by name if that's how it want to display
> them. It seems wrong for the DeviceTree code to decide that sorted by name
> is the correct order, when it is not an intrinsic order for the device.
As a long-term solution it would definitely be better to let the device
decide the order of its children. However, there's nothing like list of
device's children, such list is only constructed in the getChildren
method from all devices by checking their 'parents' attribute.

> 
> Isn't it true that patch (2) does attempt to enforce an order, by start block?
> That seems like a much more reasonable order to maintain when returning the children.
> 
> If you actually were maintaining that order, sorted by start, then obviously the code
> in patch (2) could be a lot simpler.
Same answer as above -- the list of children is constructed from all
devices and depends on their order.

-- 
Vratislav Podzimek

Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic



More information about the anaconda-patches mailing list