diff options
author | Zac Medico <zmedico@gentoo.org> | 2009-08-27 05:05:00 +0000 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2009-08-27 05:05:00 +0000 |
commit | 19da4173f212e248612b2f4f593dc2f839a24f1c (patch) | |
tree | cda571fcbad1048c583ae003a08665b61a087d7a | |
parent | 2a4b07c8d0105ea7418ea3afc9e777a7a396fc46 (diff) | |
download | portage-19da4173f212e248612b2f4f593dc2f839a24f1c.tar.gz portage-19da4173f212e248612b2f4f593dc2f839a24f1c.tar.bz2 portage-19da4173f212e248612b2f4f593dc2f839a24f1c.zip |
Fix tar_contents() to handle UnicodeEncodeError by falling back to utf_8 if
appropriate.
svn path=/main/trunk/; revision=14163
-rw-r--r-- | pym/portage/dbapi/vartree.py | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py index a1891c37e..c8a045dc4 100644 --- a/pym/portage/dbapi/vartree.py +++ b/pym/portage/dbapi/vartree.py @@ -4400,6 +4400,26 @@ def write_contents(contents, root, f): def tar_contents(contents, root, tar, protect=None, onProgress=None): os = _os_merge + + try: + for x in contents: + _unicode_encode(x, + encoding=_encodings['merge'], + errors='strict') + except UnicodeEncodeError: + # The package appears to have been merged with a + # different value of sys.getfilesystemencoding(), + # so fall back to utf_8 if appropriate. + try: + for x in contents: + _unicode_encode(x, + encoding=_encodings['fs'], + errors='strict') + except UnicodeEncodeError: + pass + else: + os = portage.os + from portage.util import normalize_path import tarfile root = normalize_path(root).rstrip(os.path.sep) + os.path.sep @@ -4447,7 +4467,8 @@ def tar_contents(contents, root, tar, protect=None, onProgress=None): tar.addfile(tarinfo) else: f = open(_unicode_encode(path, - encoding=_encodings['merge'], errors='strict'), 'rb') + encoding=object.__getattribute__(os, '_encoding'), + errors='strict'), 'rb') try: tar.addfile(tarinfo, f) finally: |