neil / rpms / python-blivet

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