neil / rpms / python-blivet

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