@@ -251,6 +251,38 @@ def __init__(self):
251
251
self .thr = threading .Thread (target = self .read_output , args = [self .pbar ], daemon = True )
252
252
self .thr .start ()
253
253
254
+ @classmethod
255
+ def should_destroy_be (cls , be_line : str , today_str : str ) -> bool :
256
+ """
257
+ Determines if a Boot Environment should be destroyed based on criteria.
258
+ Returns False if the BE is protected (active and mounted at root).
259
+ :param be_line: The BE line to check.
260
+ :param today_str: The string representation of today's date.
261
+ :return: True if the BE should be destroyed, False otherwise.
262
+ """
263
+ # Split the line into columns, handling multiple spaces
264
+ columns = be_line .split ()
265
+ if len (columns ) < 4 :
266
+ return False
267
+
268
+ be_name = columns [0 ]
269
+ active_status = columns [1 ]
270
+ mount_point = columns [2 ]
271
+
272
+ # Protect BE if it's active (N) AND mounted at root (/)
273
+ if 'N' in active_status and mount_point == '/' :
274
+ return False
275
+
276
+ if 'R' in active_status :
277
+ return False
278
+
279
+ # Apply your original deletion criteria
280
+ return (
281
+ 'backup' in be_name and
282
+ today_str not in be_name and
283
+ 'NR' not in active_status
284
+ )
285
+
254
286
255
287
def read_output (self , progress ):
256
288
"""
@@ -280,7 +312,7 @@ def read_output(self, progress):
280
312
txt = _ ("Cleaning old boot environment" )
281
313
GLib .idle_add (update_progress , progress , fraction , txt )
282
314
for be in bectl .get_be_list ():
283
- if 'backup' in be and today not in be and 'NR' not in be :
315
+ if self . should_destroy_be ( be , today ) :
284
316
bectl .destroy_be (be .split ()[0 ])
285
317
backup_name = datetime .datetime .now ().strftime (f"{ distro .version ()} -backup-%Y-%m-%d-%H-%M" )
286
318
txt = _ ("Creating boot environment" )
0 commit comments