[PATCH 2/2] Make prefering leaves the default in getDeviceByPath (#1122081)
mulhern
amulhern at redhat.com
Fri Aug 29 21:26:34 UTC 2014
Resolves: fed#1122081
Preferring leaves was the default until commit
822d92457e36768b9daa6a3ec689e494e9ba07df which deliberately but
mistakenly reversed the preference.
Signed-off-by: mulhern <amulhern at redhat.com>
---
blivet/devicetree.py | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/blivet/devicetree.py b/blivet/devicetree.py
index 508e533..4b60ef9 100644
--- a/blivet/devicetree.py
+++ b/blivet/devicetree.py
@@ -2341,6 +2341,9 @@ class DeviceTree(object):
def getDeviceByPath(self, path, incomplete=False, hidden=False):
""" Return a device with a matching path.
+ If there is more than one device with a matching path,
+ prefer a leaf device to a non-leaf device.
+
:param str path: the path to match
:param bool incomplete: include incomplete devices in search
:param bool hidden: include hidden devices in search
@@ -2351,7 +2354,11 @@ class DeviceTree(object):
result = None
if path:
devices = self._filterDevices(incomplete=incomplete, hidden=hidden)
- result = next((d for d in devices if d.path == path or \
+
+ # The usual order of the devices list is one where leaves are at
+ # the end. So that the search can prefer leaves to interior nodes
+ # the list that is searched is the reverse of the devices list.
+ result = next((d for d in reversed(list(devices)) if d.path == path or \
((d.type == "lvmlv" or d.type == "lvmvg") and d.path == path.replace("--","-"))),
None)
--
1.9.3
More information about the anaconda-patches
mailing list