From c7df44e774a0c1400b4c91123146fa4396644f91 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Thu, 6 Aug 2009 05:35:14 +0000 Subject: Do not pass unicode strings into os.walk calls, since it can cause internal os.path.join calls to raise UnicodeDecodeError. svn path=/main/trunk/; revision=13926 --- pym/portage/__init__.py | 11 +++++++++++ pym/portage/cache/ebuild_xattr.py | 9 ++++++++- pym/portage/dbapi/vartree.py | 6 ++++++ pym/portage/env/loaders.py | 6 ++++++ pym/portage/manifest.py | 20 +++++++++++++++++--- pym/portage/sets/files.py | 15 ++++++++++++++- pym/portage/update.py | 6 ++++++ pym/portage/util.py | 5 +++++ 8 files changed, 73 insertions(+), 5 deletions(-) (limited to 'pym') diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py index a152293d8..a959207c4 100644 --- a/pym/portage/__init__.py +++ b/pym/portage/__init__.py @@ -4901,6 +4901,11 @@ def digestcheck(myfiles, mysettings, strict=0, justmanifest=0): """ epatch will just grab all the patches out of a directory, so we have to make sure there aren't any foreign files that it might grab.""" filesdir = os.path.join(pkgdir, "files") + if isinstance(filesdir, unicode): + # Avoid UnicodeDecodeError raised from + # os.path.join when called by os.walk. + filesdir = filesdir.encode('utf_8', 'replace') + for parent, dirs, files in os.walk(filesdir): for d in dirs: if d.startswith(".") or d == "CVS": @@ -5158,6 +5163,12 @@ def _post_src_install_uid_fix(mysettings): os.system("chflags -R nosunlnk,nouunlnk %s 2>/dev/null" % \ (_shell_quote(mysettings["D"]),)) + destdir = mysettings["D"] + if isinstance(destdir, unicode): + # Avoid UnicodeDecodeError raised from + # os.path.join when called by os.walk. + destdir = destdir.encode('utf_8', 'replace') + for parent, dirs, files in os.walk(mysettings["D"]): for fname in chain(dirs, files): fpath = os.path.join(parent, fname) diff --git a/pym/portage/cache/ebuild_xattr.py b/pym/portage/cache/ebuild_xattr.py index 83ed8a783..98e848651 100644 --- a/pym/portage/cache/ebuild_xattr.py +++ b/pym/portage/cache/ebuild_xattr.py @@ -153,7 +153,14 @@ class database(fs_template.FsBased): return os.path.exists(self.__get_path(cpv)) def __iter__(self): - for root,dirs,files in os.walk(self.portdir): + + portdir = self.portdir + if isinstance(portdir, unicode): + # Avoid UnicodeDecodeError raised from + # os.path.join when called by os.walk. + portdir = portdir.encode('utf_8', 'replace') + + for root, dirs, files in os.walk(portdir): for file in files: if file[-7:] == '.ebuild': cat = os.path.basename(os.path.dirname(root)) diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py index b9dba438b..c6374cdf9 100644 --- a/pym/portage/dbapi/vartree.py +++ b/pym/portage/dbapi/vartree.py @@ -3221,6 +3221,12 @@ class dblink(object): myfilelist = [] mylinklist = [] paths_with_newlines = [] + + if isinstance(srcroot, unicode): + # Avoid UnicodeDecodeError raised from + # os.path.join when called by os.walk. + srcroot = srcroot.encode('utf_8', 'replace') + srcroot_len = len(srcroot) def onerror(e): raise diff --git a/pym/portage/env/loaders.py b/pym/portage/env/loaders.py index 7b4d72721..854304125 100644 --- a/pym/portage/env/loaders.py +++ b/pym/portage/env/loaders.py @@ -39,6 +39,12 @@ def RecursiveFileLoader(filename): @rtype: list @returns: List of files to process """ + + if isinstance(filename, unicode): + # Avoid UnicodeDecodeError raised from + # os.path.join when called by os.walk. + filename = filename.encode('utf_8', 'replace') + try: st = os.stat(filename) except OSError: diff --git a/pym/portage/manifest.py b/pym/portage/manifest.py index 80a0c1642..a717d5841 100644 --- a/pym/portage/manifest.py +++ b/pym/portage/manifest.py @@ -306,7 +306,14 @@ class Manifest(object): cpvlist = [] pn = os.path.basename(self.pkgdir.rstrip(os.path.sep)) cat = self._pkgdir_category() - for pkgdir, pkgdir_dirs, pkgdir_files in os.walk(self.pkgdir): + + pkgdir = self.pkgdir + if isinstance(pkgdir, unicode): + # Avoid UnicodeDecodeError raised from + # os.path.join when called by os.walk. + pkgdir = pkgdir.encode('utf_8', 'replace') + + for pkgdir, pkgdir_dirs, pkgdir_files in os.walk(pkgdir): break for f in pkgdir_files: if f[:1] == ".": @@ -334,8 +341,15 @@ class Manifest(object): continue self.fhashdict[mytype][f] = perform_multiple_checksums(self.pkgdir+f, self.hashes) recursive_files = [] - cut_len = len(os.path.join(self.pkgdir, "files") + os.sep) - for parentdir, dirs, files in os.walk(os.path.join(self.pkgdir, "files")): + + pkgdir = self.pkgdir + if isinstance(pkgdir, unicode): + # Avoid UnicodeDecodeError raised from + # os.path.join when called by os.walk. + pkgdir = pkgdir.encode('utf_8', 'replace') + + cut_len = len(os.path.join(pkgdir, "files") + os.sep) + for parentdir, dirs, files in os.walk(os.path.join(pkgdir, "files")): for f in files: full_path = os.path.join(parentdir, f) recursive_files.append(full_path[cut_len:]) diff --git a/pym/portage/sets/files.py b/pym/portage/sets/files.py index f4ecbae7c..f0b6fed58 100644 --- a/pym/portage/sets/files.py +++ b/pym/portage/sets/files.py @@ -125,9 +125,22 @@ class StaticFileSet(EditablePackageSet): directory = self._repopath_sub.sub(trees["porttree"].dbapi.treemap[match.groupdict()["reponame"]], directory) except KeyError: raise SetConfigError(_("Could not find repository '%s'") % match.groupdict()["reponame"]) + + if isinstance(directory, unicode): + # Avoid UnicodeDecodeError raised from + # os.path.join when called by os.walk. + directory_unicode = directory + directory = directory.encode('utf_8', 'replace') + else: + directory_unicode = unicode(directory, + encoding='utf_8', errors='replace') + if os.path.isdir(directory): directory = normalize_path(directory) for parent, dirs, files in os.walk(directory): + if not isinstance(parent, unicode): + parent = unicode(parent, + encoding='utf_8', errors='replace') for d in dirs[:]: if d[:1] == '.': dirs.remove(d) @@ -140,7 +153,7 @@ class StaticFileSet(EditablePackageSet): if filename.endswith(".metadata"): continue filename = os.path.join(parent, - filename)[1 + len(directory):] + filename)[1 + len(directory_unicode):] myname = name_pattern.replace("$name", filename) myname = myname.replace("${name}", filename) rValue[myname] = StaticFileSet( diff --git a/pym/portage/update.py b/pym/portage/update.py index c7001803a..4e309e401 100644 --- a/pym/portage/update.py +++ b/pym/portage/update.py @@ -146,6 +146,12 @@ def update_config_files(config_root, protect, protect_mask, update_iter): protect - list of paths from CONFIG_PROTECT protect_mask - list of paths from CONFIG_PROTECT_MASK update_iter - list of update commands as returned from parse_updates()""" + + if isinstance(config_root, unicode): + # Avoid UnicodeDecodeError raised from + # os.path.join when called by os.walk. + config_root = config_root.encode('utf_8', 'replace') + config_root = normalize_path(config_root) update_files = {} file_contents = {} diff --git a/pym/portage/util.py b/pym/portage/util.py index f1bff1d40..5b860218d 100644 --- a/pym/portage/util.py +++ b/pym/portage/util.py @@ -780,6 +780,11 @@ def apply_recursive_permissions(top, uid=-1, gid=-1, Returns True if all permissions are applied and False if some are left unapplied.""" + if isinstance(top, unicode): + # Avoid UnicodeDecodeError raised from + # os.path.join when called by os.walk. + top = top.encode('utf_8', 'replace') + if onerror is None: # Default behavior is to dump errors to stderr so they won't # go unnoticed. Callers can pass in a quiet instance. -- cgit v1.2.3-1-g7c22