commit:     66f64d08ffb13ca24cfc11584fe667b1c391fbe8
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Thu Dec  1 06:31:53 2022 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Thu Dec  1 07:08:02 2022 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=66f64d08

vartree: use ewarn if merging despite collisions

Use ewarn, not eerror, if merge is going ahead despite collisions.

Collisions aren't always fatal - say if FEATURES="protect-owned unmerge-orphans"
and the collision is over an orphaned file.

This changes the colors used once we discover that all relevant files
are orphaned to be warning rather than an error, to make it less scary
and distinguish from other situations.

Closes: https://github.com/gentoo/portage/pull/952
Signed-off-by: Sam James <sam <AT> gentoo.org>

 NEWS                         |  4 +++-
 lib/portage/dbapi/vartree.py | 18 +++++++++++++++---
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/NEWS b/NEWS
index d64fcac91..a907526aa 100644
--- a/NEWS
+++ b/NEWS
@@ -2,7 +2,9 @@ portage-3.0.41 (UNRELEASED)
 --------------
 
 Features:
-* TODO
+* vartree: On collisions which are non-fatal (e.g. orphaned files when using
+  FEATURES="protect-owned"), Portage now has friendlier output
+  by using ewarn rather than eerror.
 
 Bug fixes:
 * TODO

diff --git a/lib/portage/dbapi/vartree.py b/lib/portage/dbapi/vartree.py
index a95d60691..139424c0a 100644
--- a/lib/portage/dbapi/vartree.py
+++ b/lib/portage/dbapi/vartree.py
@@ -4187,6 +4187,9 @@ class dblink:
     def _eqawarn(self, phase, lines):
         self._elog("eqawarn", phase, lines)
 
+    def _ewarn(self, phase, lines):
+        self._elog("ewarn", phase, lines)
+
     def _eerror(self, phase, lines):
         self._elog("eerror", phase, lines)
 
@@ -4388,6 +4391,9 @@ class dblink:
                     ],
                 )
 
+        def ewarn(lines):
+            self._ewarn("preinst", lines)
+
         def eerror(lines):
             self._eerror("preinst", lines)
 
@@ -4884,6 +4890,10 @@ class dblink:
                 finally:
                     self.unlockdb()
 
+                collision_message_type = ewarn
+                if collision_protect or protect_owned and owners:
+                    collision_message_type = eerror
+
                 for pkg, owned_files in owners.items():
                     msg = []
                     msg.append(pkg_info_strs[pkg.mycpv])
@@ -4892,10 +4902,10 @@ class dblink:
                             "\t%s" % os.path.join(destroot, 
f.lstrip(os.path.sep))
                         )
                     msg.append("")
-                    eerror(msg)
+                    collision_message_type(msg)
 
                 if not owners:
-                    eerror(
+                    collision_message_type(
                         [_("None of the installed" " packages claim the 
file(s)."), ""]
                     )
 
@@ -4935,10 +4945,12 @@ class dblink:
                 " If necessary, refer to your elog "
                 "messages for the whole content of the above message."
             )
-            eerror(wrap(msg, 70))
 
             if abort:
+                eerror(wrap(msg, 70))
                 return 1
+            else:
+                ewarn(wrap(msg, 70))
 
         # The merge process may move files out of the image directory,
         # which causes invalidation of the .installed flag.

Reply via email to