Do not pass unicode strings into os.walk calls, since it can cause
authorZac Medico <zmedico@gentoo.org>
Thu, 6 Aug 2009 05:35:14 +0000 (05:35 -0000)
committerZac Medico <zmedico@gentoo.org>
Thu, 6 Aug 2009 05:35:14 +0000 (05:35 -0000)
internal os.path.join calls to raise UnicodeDecodeError.

svn path=/main/trunk/; revision=13926

pym/portage/__init__.py
pym/portage/cache/ebuild_xattr.py
pym/portage/dbapi/vartree.py
pym/portage/env/loaders.py
pym/portage/manifest.py
pym/portage/sets/files.py
pym/portage/update.py
pym/portage/util.py

index a152293d8e982407ccb7ecd4d30cb1edd6d1cf81..a959207c41e1053bc57e613208be613e9b2c3740 100644 (file)
@@ -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)
index 83ed8a783c18a30dfc5d3ea76aa11dfba9d8d16a..98e848651a9ac819815069a28f4a174c9524a383 100644 (file)
@@ -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))
index b9dba438bfc921dd15e2114869782615d27687d6..c6374cdf97a24b5e225e76aa38d2fbe036100969 100644 (file)
@@ -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
index 7b4d727213bb8face02bc92b62af196d4de5614e..854304125f331d8794d8483fd72d90287a95be75 100644 (file)
@@ -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:
index 80a0c16424c8a5167c8b0706646846284dc0adb4..a717d584194f5f395c9212eae64b3843b2fc233a 100644 (file)
@@ -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:])
index f4ecbae7cd88b7c7f0f5a07b3c27cd441ee60547..f0b6fed58310f1ed8089d108778f1b0bab6d9065 100644 (file)
@@ -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(
index c7001803ac7995d35f4fdfb67c476d94963975a3..4e309e4019cf00b08c6d67fed840822131c7912e 100644 (file)
@@ -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 = {}
index f1bff1d4086869e51bf6bb6274240c30aaf77e4b..5b860218d21e4921d5e6a4fde118f9422aee83d4 100644 (file)
@@ -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.