neil / rpms / python-blivet

Forked from rpms/python-blivet a year ago
Clone
93a1d2
From 62af1d7f96b8ed8eb8f2732787576161ae5da79f Mon Sep 17 00:00:00 2001
93a1d2
From: Vojtech Trefny <vtrefny@redhat.com>
93a1d2
Date: Thu, 13 Oct 2022 10:47:52 +0200
93a1d2
Subject: [PATCH] Revert "Remove the Blivet.roots attribute"
93a1d2
93a1d2
This reverts commit 19a826073345ca6b57a8f9a95ec855892320300e.
93a1d2
---
93a1d2
 blivet/blivet.py        | 21 +++++++++++++++++++++
93a1d2
 blivet/devicefactory.py |  3 +++
93a1d2
 2 files changed, 24 insertions(+)
93a1d2
93a1d2
diff --git a/blivet/blivet.py b/blivet/blivet.py
93a1d2
index bf72ee9c..dc066b03 100644
93a1d2
--- a/blivet/blivet.py
93a1d2
+++ b/blivet/blivet.py
93a1d2
@@ -88,6 +88,7 @@ class Blivet(object):
93a1d2
         self.devicetree = DeviceTree(ignored_disks=self.ignored_disks,
93a1d2
                                      exclusive_disks=self.exclusive_disks,
93a1d2
                                      disk_images=self.disk_images)
93a1d2
+        self.roots = []
93a1d2
 
93a1d2
     @property
93a1d2
     def short_product_name(self):
93a1d2
@@ -1314,5 +1315,25 @@ class Blivet(object):
93a1d2
             p = partition.disk.format.parted_disk.getPartitionByPath(partition.path)
93a1d2
             partition.parted_partition = p
93a1d2
 
93a1d2
+        for root in new.roots:
93a1d2
+            root.swaps = [new.devicetree.get_device_by_id(d.id, hidden=True) for d in root.swaps]
93a1d2
+            root.swaps = [s for s in root.swaps if s]
93a1d2
+
93a1d2
+            removed = set()
93a1d2
+            for (mountpoint, old_dev) in root.mounts.items():
93a1d2
+                if old_dev is None:
93a1d2
+                    continue
93a1d2
+
93a1d2
+                new_dev = new.devicetree.get_device_by_id(old_dev.id, hidden=True)
93a1d2
+                if new_dev is None:
93a1d2
+                    # if the device has been removed don't include this
93a1d2
+                    # mountpoint at all
93a1d2
+                    removed.add(mountpoint)
93a1d2
+                else:
93a1d2
+                    root.mounts[mountpoint] = new_dev
93a1d2
+
93a1d2
+            for mnt in removed:
93a1d2
+                del root.mounts[mnt]
93a1d2
+
93a1d2
         log.debug("finished Blivet copy")
93a1d2
         return new
93a1d2
diff --git a/blivet/devicefactory.py b/blivet/devicefactory.py
93a1d2
index 8105bfc7..6f460f6d 100644
93a1d2
--- a/blivet/devicefactory.py
93a1d2
+++ b/blivet/devicefactory.py
93a1d2
@@ -383,6 +383,7 @@ class DeviceFactory(object):
93a1d2
         # used for error recovery
93a1d2
         self.__devices = []
93a1d2
         self.__actions = []
93a1d2
+        self.__roots = []
93a1d2
 
93a1d2
     def _is_container_encrypted(self):
93a1d2
         return all(isinstance(p, LUKSDevice) for p in self.device.container.parents)
93a1d2
@@ -994,10 +995,12 @@ class DeviceFactory(object):
93a1d2
         _blivet_copy = self.storage.copy()
93a1d2
         self.__devices = _blivet_copy.devicetree._devices
93a1d2
         self.__actions = _blivet_copy.devicetree._actions
93a1d2
+        self.__roots = _blivet_copy.roots
93a1d2
 
93a1d2
     def _revert_devicetree(self):
93a1d2
         self.storage.devicetree._devices = self.__devices
93a1d2
         self.storage.devicetree._actions = self.__actions
93a1d2
+        self.storage.roots = self.__roots
93a1d2
 
93a1d2
 
93a1d2
 class PartitionFactory(DeviceFactory):
93a1d2
-- 
93a1d2
2.38.1
93a1d2