diff options
author | Zac Medico <zmedico@gentoo.org> | 2011-09-03 16:46:09 -0700 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2011-09-03 16:46:09 -0700 |
commit | a62537685afbe492d4686cb6a636cbe556fe74d9 (patch) | |
tree | 6209e4af4841a29003f2485ae0654a0df9216ec0 /pym/portage/dbapi/vartree.py | |
parent | fe01dc23324660ae18c732cfacd458c3faf50ad7 (diff) | |
download | portage-a62537685afbe492d4686cb6a636cbe556fe74d9.tar.gz portage-a62537685afbe492d4686cb6a636cbe556fe74d9.tar.bz2 portage-a62537685afbe492d4686cb6a636cbe556fe74d9.zip |
Handle symlink content with bad encoding.
This will fix bug #381629. The case is tested in tests/emerge. During
forced charset conversion, 'ascii' codec is forced, since otherwise we
somehow end up with the wrongly encoded file names when running the
test with Python 3.2 (which causes encoding problems for quickpkg when
it calls tarfile.gettarinfo).
Diffstat (limited to 'pym/portage/dbapi/vartree.py')
-rw-r--r-- | pym/portage/dbapi/vartree.py | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py index 3a6d99f02..bafe13885 100644 --- a/pym/portage/dbapi/vartree.py +++ b/pym/portage/dbapi/vartree.py @@ -3304,7 +3304,7 @@ class dblink(object): new_parent = _unicode_decode(parent, encoding=_encodings['merge'], errors='replace') new_parent = _unicode_encode(new_parent, - encoding=_encodings['merge'], errors='backslashreplace') + encoding='ascii', errors='backslashreplace') new_parent = _unicode_decode(new_parent, encoding=_encodings['merge'], errors='replace') os.rename(parent, new_parent) @@ -3322,7 +3322,7 @@ class dblink(object): new_fname = _unicode_decode(fname, encoding=_encodings['merge'], errors='replace') new_fname = _unicode_encode(new_fname, - encoding=_encodings['merge'], errors='backslashreplace') + encoding='ascii', errors='backslashreplace') new_fname = _unicode_decode(new_fname, encoding=_encodings['merge'], errors='replace') new_fpath = os.path.join(parent, new_fname) @@ -3994,11 +3994,29 @@ class dblink(object): if stat.S_ISLNK(mymode): # we are merging a symbolic link + # The file name of mysrc and the actual file that it points to + # will have earlier been forcefully converted to the 'merge' + # encoding if necessary, but the content of the symbolic link + # may need to be forcefully converted here. + myto = _os.readlink(_unicode_encode(mysrc, + encoding=_encodings['merge'], errors='strict')) + try: + myto = _unicode_decode(myto, + encoding=_encodings['merge'], errors='strict') + except UnicodeDecodeError: + myto = _unicode_decode(myto, encoding=_encodings['merge'], + errors='replace') + myto = _unicode_encode(myto, encoding='ascii', + errors='backslashreplace') + myto = _unicode_decode(myto, encoding=_encodings['merge'], + errors='replace') + os.unlink(mysrc) + os.symlink(myto, mysrc) + myabsto = abssymlink(mysrc) if myabsto.startswith(srcroot): myabsto = myabsto[len(srcroot):] myabsto = myabsto.lstrip(sep) - myto = os.readlink(mysrc) if self.settings and self.settings["D"]: if myto.startswith(self.settings["D"]): myto = myto[len(self.settings["D"]):] @@ -4454,6 +4472,7 @@ def write_contents(contents, root, f): def tar_contents(contents, root, tar, protect=None, onProgress=None): os = _os_merge + encoding = _encodings['merge'] try: for x in contents: @@ -4473,6 +4492,7 @@ def tar_contents(contents, root, tar, protect=None, onProgress=None): pass else: os = portage.os + encoding = _encodings['fs'] root = normalize_path(root).rstrip(os.path.sep) + os.path.sep id_strings = {} @@ -4524,7 +4544,7 @@ def tar_contents(contents, root, tar, protect=None, onProgress=None): f.close() else: f = open(_unicode_encode(path, - encoding=object.__getattribute__(os, '_encoding'), + encoding=encoding, errors='strict'), 'rb') try: tar.addfile(tarinfo, f) |