From 19da4173f212e248612b2f4f593dc2f839a24f1c Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Thu, 27 Aug 2009 05:05:00 +0000 Subject: Fix tar_contents() to handle UnicodeEncodeError by falling back to utf_8 if appropriate. svn path=/main/trunk/; revision=14163 --- pym/portage/dbapi/vartree.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'pym') 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: -- cgit v1.2.3-1-g7c22