Blob Blame History Raw
From 31f95734f0d6f90f256754377207f5373ff9015c Mon Sep 17 00:00:00 2001
From: "Bryn M. Reeves" <bmr@redhat.com>
Date: Tue, 14 Jun 2022 07:54:29 -0400
Subject: [PATCH 4/5] boom.bootloader: do not allow deletion of read-only boot
 entries

Currently when attempting to delete an entry that has been marked
read-only boom generates a misleading error message:

  # boom delete 7fce1e5
  Entry does not exist: /boot/loader/entries/619c4d9f1efa4cf7bd76f149f12138a0-7fce1e5-5.14.0-108.el9.x86_64.conf

Boom should not attempt to delete entries that are marked read-only;
these are either system provided entries, or entries that have been
modified outside of boom's control. Reject attempts to delete these
with an error that indicates the reason they cannot be removed:

  # boom delete f6f8df5
  Cannot delete read-only boot entry: /boot/loader/entries/68f613d8774e41e792fad28212cfedae-4.18.0-348.el8.x86_64.conf

Resolves: #10

Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
(cherry picked from commit 42f66737e1d7dec432cd7fc330f87304a585c308)
---
 boom/bootloader.py | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/boom/bootloader.py b/boom/bootloader.py
index bbf7fd5..a81ea84 100644
--- a/boom/bootloader.py
+++ b/boom/bootloader.py
@@ -2445,6 +2445,10 @@ class BootEntry(object):
             :raises: ``OsError`` if an error occurs removing the file or
                      ``ValueError`` if the entry does not exist.
         """
+        if self.read_only:
+            raise ValueError("Cannot delete read-only boot "
+                             "entry: %s" % self._last_path)
+
         if not path_exists(self._entry_path):
             raise ValueError("Entry does not exist: %s" % self._entry_path)
         try:
-- 
2.34.3