commit:     1d3b22621d332331da6e48ae653e983406f44e5f
Author:     gcarq <egger.m <AT> protonmail <DOT> com>
AuthorDate: Fri Sep  1 16:46:23 2023 +0000
Commit:     Mike Gilbert <floppym <AT> gentoo <DOT> org>
CommitDate: Fri Sep  1 19:13:27 2023 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=1d3b2262

emerge: ensure paths are UTF-8 encoded in _needs_move()

Bug: https://bugs.gentoo.org/913103
Closes: https://github.com/gentoo/portage/pull/1086
Signed-off-by: Michael Egger <egger.m <AT> protonmail.com>
Signed-off-by: Mike Gilbert <floppym <AT> gentoo.org>

 NEWS                         | 2 ++
 lib/portage/dbapi/vartree.py | 7 +++++--
 lib/portage/util/movefile.py | 5 +++--
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/NEWS b/NEWS
index aa7ffd2652..65e75759bf 100644
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,8 @@ Features:
 Bug fixes:
 * Prevent gpg from removing /dev/null when unlocking signing key (bug #912808).
 
+* emerge: ensure paths are UTF-8 encoded in _needs_move() (bug #913103).
+
 portage-3.0.51 (2023-08-20)
 --------------
 

diff --git a/lib/portage/dbapi/vartree.py b/lib/portage/dbapi/vartree.py
index dac3508801..7d1bba712e 100644
--- a/lib/portage/dbapi/vartree.py
+++ b/lib/portage/dbapi/vartree.py
@@ -6273,12 +6273,15 @@ class dblink:
         if mydmode is None or not stat.S_ISREG(mydmode) or mymode != mydmode:
             return True
 
+        src_bytes = _unicode_encode(mysrc, encoding=_encodings["fs"], 
errors="strict")
+        dest_bytes = _unicode_encode(mydest, encoding=_encodings["fs"], 
errors="strict")
+
         if "xattr" in self.settings.features:
             excluded_xattrs = self.settings.get("PORTAGE_XATTR_EXCLUDE", "")
-            if not _cmpxattr(mysrc, mydest, exclude=excluded_xattrs):
+            if not _cmpxattr(src_bytes, dest_bytes, exclude=excluded_xattrs):
                 return True
 
-        return not filecmp.cmp(mysrc, mydest, shallow=False)
+        return not filecmp.cmp(src_bytes, dest_bytes, shallow=False)
 
 
 def merge(

diff --git a/lib/portage/util/movefile.py b/lib/portage/util/movefile.py
index e2f19ba92b..75100a3acd 100644
--- a/lib/portage/util/movefile.py
+++ b/lib/portage/util/movefile.py
@@ -105,10 +105,11 @@ def _copyxattr(src, dest, exclude=None):
             )
 
 
-def _cmpxattr(src, dest, exclude=None):
+def _cmpxattr(src: bytes, dest: bytes, exclude=None) -> bool:
     """
     Compares extended attributes between |src| and |dest| and returns True
-    if they are equal or xattrs are not supported, False otherwise
+    if they are equal or xattrs are not supported, False otherwise.
+    Assumes all given paths are UTF-8 encoded.
     """
     try:
         src_attrs = xattr.list(src)

Reply via email to