aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2023-10-23 10:14:21 -0700
committerZac Medico <zmedico@gentoo.org>2023-10-23 18:48:56 -0700
commit92f34ea2f00ea68b2b5c8374ba6b38287adb1628 (patch)
tree1e2ed40f5016763192551b50e1a468f064efe79b
parentcreate_trees: Handle bytes arguments for utf8_mode (diff)
downloadportage-92f34ea2f00ea68b2b5c8374ba6b38287adb1628.tar.gz
portage-92f34ea2f00ea68b2b5c8374ba6b38287adb1628.tar.bz2
portage-92f34ea2f00ea68b2b5c8374ba6b38287adb1628.zip
StaticFileSet: Fix os.walk for utf8_mode
Bug: https://bugs.gentoo.org/916182 Signed-off-by: Zac Medico <zmedico@gentoo.org>
-rw-r--r--lib/portage/_sets/files.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/portage/_sets/files.py b/lib/portage/_sets/files.py
index 46c39b3c7..1b9cc6016 100644
--- a/lib/portage/_sets/files.py
+++ b/lib/portage/_sets/files.py
@@ -1,10 +1,11 @@
-# Copyright 2007-2020 Gentoo Authors
+# Copyright 2007-2023 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
import errno
import re
from itertools import chain
+import portage
from portage import os
from portage import _encodings
from portage import _unicode_decode
@@ -176,6 +177,14 @@ class StaticFileSet(EditablePackageSet):
directory = normalize_path(directory)
for parent, dirs, files in os.walk(directory):
+ if portage.utf8_mode:
+ dirs_orig = dirs
+ omit_dir = lambda d: dirs_orig.remove(os.fsdecode(d))
+ parent = os.fsencode(parent)
+ dirs = [os.fsencode(value) for value in dirs]
+ files = [os.fsencode(value) for value in files]
+ else:
+ omit_dir = lambda d: dirs.remove(d)
try:
parent = _unicode_decode(
parent, encoding=_encodings["fs"], errors="strict"
@@ -184,7 +193,7 @@ class StaticFileSet(EditablePackageSet):
continue
for d in dirs[:]:
if d in vcs_dirs or d.startswith(b".") or d.endswith(b"~"):
- dirs.remove(d)
+ omit_dir(d)
for filename in files:
try:
filename = _unicode_decode(