neil / rpms / python-blivet

Forked from rpms/python-blivet a year ago
Clone

Blame SOURCES/0005-Revert-Remove-the-Blivet.roots-attribute.patch

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