Skip to content

Commit f2843f8

Browse files
evan-goodekontura
authored andcommitted
bootc: Check whether protected paths will be modified
For #2199. Requires libdnf 0.75.0 with the new `usr_drift_protected_paths` option.
1 parent bf07219 commit f2843f8

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

dnf/cli/cli.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from collections.abc import Sequence
3030
except ImportError:
3131
from collections import Sequence
32+
from collections import defaultdict
3233
import datetime
3334
import logging
3435
import operator
@@ -245,6 +246,24 @@ def do_transaction(self, display=()):
245246
"Keep in mind that changes to /etc and /var will still persist, and packages "
246247
"commonly modify these directories."))
247248
self._persistence = libdnf.transaction.TransactionPersistence_TRANSIENT
249+
250+
# Check whether the transaction modifies usr_drift_protected_paths
251+
transaction_protected_paths = defaultdict(list)
252+
for pkg in trans:
253+
for pkg_file_path in sorted(pkg.files):
254+
for protected_path in self.conf.usr_drift_protected_paths:
255+
if pkg_file_path.startswith("%s/" % protected_path) or pkg_file_path == protected_path:
256+
transaction_protected_paths[pkg.nevra].append(pkg_file_path)
257+
if transaction_protected_paths:
258+
logger.info(_('This operation would modify the following paths, possibly introducing '
259+
'inconsistencies when the transient overlay on /usr is discarded. See the '
260+
'usr_drift_protected_paths configuration option for more information.'))
261+
for nevra, protected_paths in transaction_protected_paths.items():
262+
logger.info(nevra)
263+
for protected_path in protected_paths:
264+
logger.info(" %s" % protected_path)
265+
raise CliError(_("Operation aborted."))
266+
248267
else:
249268
# Not a bootc transaction.
250269
if self.conf.persistence == "transient":

0 commit comments

Comments
 (0)