[blivet:rhel7/master 5/8] Make the hide method itself unrecursive (#1043763)

mulhern amulhern at redhat.com
Mon Feb 24 17:42:00 UTC 2014


Related: rhbz#1043763

Find all the devices dependents before beginning to remove them.

Signed-off-by: mulhern <amulhern at redhat.com>
---
 blivet/devicetree.py | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/blivet/devicetree.py b/blivet/devicetree.py
index fa4aada..10648d2 100644
--- a/blivet/devicetree.py
+++ b/blivet/devicetree.py
@@ -1831,17 +1831,29 @@ class DeviceTree(object):
                 finally:
                     self._actions.remove(action)
 
+        def getDependents(device, seen=[]):
+            """Get all devices that depend on this device. Assumes that
+               the graph (where the nodes are devices and the edges are
+               dependency relationships) may contain cycles.
+
+               The device itself is included among its dependents.
+            """
+            seen = seen + [device]
+            for d in self.getChildren(device):
+                if not d in seen:
+                    seen = getDependents(d, seen)
+            return seen
+
         if device in self._hidden:
             return
 
-        for d in self.getChildren(device):
-            self.hide(d)
+        dependents = getDependents(device)
 
-        remove_actions(device)
+        for d in dependents:
+            remove_actions(d)
 
-        # XXX modifications that do not require actions, like setting a
-        #     mountpoint, will not be reversed here
-        hide_device(device)
+        for d in dependents:
+            hide_device(d)
 
     def unhide(self, device):
         # the hidden list should be in leaves-first order
-- 
1.8.3.1



More information about the anaconda-patches mailing list