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