1 |
commit: 4198da0184aaec30c41f2e5d2c7af71c4d35b662 |
2 |
Author: Zac Medico <zmedico <AT> gentoo <DOT> org> |
3 |
AuthorDate: Fri Oct 28 18:03:02 2011 +0000 |
4 |
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> |
5 |
CommitDate: Fri Oct 28 18:03:02 2011 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=4198da01 |
7 |
|
8 |
quickpkg: fix unicode for bug #388773 |
9 |
|
10 |
--- |
11 |
pym/portage/dbapi/vartree.py | 41 ++++++++++++++++++++++++++++++++++++++++- |
12 |
1 files changed, 40 insertions(+), 1 deletions(-) |
13 |
|
14 |
diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py |
15 |
index 7f94cc5..e719062 100644 |
16 |
--- a/pym/portage/dbapi/vartree.py |
17 |
+++ b/pym/portage/dbapi/vartree.py |
18 |
@@ -31,6 +31,7 @@ portage.proxy.lazyimport.lazyimport(globals(), |
19 |
'portage.util._dyn_libs.LinkageMapELF:LinkageMapELF@LinkageMap', |
20 |
'portage.versions:best,catpkgsplit,catsplit,cpv_getkey,pkgcmp,' + \ |
21 |
'_pkgsplit@pkgsplit', |
22 |
+ 'tarfile', |
23 |
) |
24 |
|
25 |
from portage.const import CACHE_PATH, CONFIG_MEMORY_FILE, \ |
26 |
@@ -61,10 +62,12 @@ from _emerge.MiscFunctionsProcess import MiscFunctionsProcess |
27 |
|
28 |
import errno |
29 |
import gc |
30 |
+import grp |
31 |
import io |
32 |
from itertools import chain |
33 |
import logging |
34 |
import os as _os |
35 |
+import pwd |
36 |
import re |
37 |
import shutil |
38 |
import stat |
39 |
@@ -4501,6 +4504,7 @@ def tar_contents(contents, root, tar, protect=None, onProgress=None): |
40 |
os = portage.os |
41 |
encoding = _encodings['fs'] |
42 |
|
43 |
+ tar.encoding = encoding |
44 |
root = normalize_path(root).rstrip(os.path.sep) + os.path.sep |
45 |
id_strings = {} |
46 |
maxval = len(contents) |
47 |
@@ -4534,7 +4538,42 @@ def tar_contents(contents, root, tar, protect=None, onProgress=None): |
48 |
# recorded as a real directory in the tar file to ensure that tar |
49 |
# can properly extract it's children. |
50 |
live_path = os.path.realpath(live_path) |
51 |
- tarinfo = tar.gettarinfo(live_path, arcname) |
52 |
+ lst = os.lstat(live_path) |
53 |
+ |
54 |
+ # Since os.lstat() inside TarFile.gettarinfo() can trigger a |
55 |
+ # UnicodeEncodeError when python has something other than utf_8 |
56 |
+ # return from sys.getfilesystemencoding() (as in bug #388773), |
57 |
+ # we implement the needed functionality here, using the result |
58 |
+ # of our successful lstat call. An alternative to this would be |
59 |
+ # to pass in the fileobj argument to TarFile.gettarinfo(), so |
60 |
+ # that it could use fstat instead of lstat. However, that would |
61 |
+ # have the unwanted effect of dereferencing symlinks. |
62 |
+ |
63 |
+ tarinfo = tar.tarinfo() |
64 |
+ tarinfo.name = arcname |
65 |
+ tarinfo.mode = lst.st_mode |
66 |
+ tarinfo.uid = lst.st_uid |
67 |
+ tarinfo.gid = lst.st_gid |
68 |
+ tarinfo.size = lst.st_size |
69 |
+ tarinfo.mtime = lst.st_mtime |
70 |
+ tarinfo.linkname = "" |
71 |
+ if stat.S_ISREG(lst.st_mode): |
72 |
+ tarinfo.type = tarfile.REGTYPE |
73 |
+ elif stat.S_ISDIR(lst.st_mode): |
74 |
+ tarinfo.type = tarfile.DIRTYPE |
75 |
+ elif stat.S_ISLNK(lst.st_mode): |
76 |
+ tarinfo.type = tarfile.SYMTYPE |
77 |
+ tarinfo.linkname = os.readlink(live_path) |
78 |
+ else: |
79 |
+ continue |
80 |
+ try: |
81 |
+ tarinfo.uname = pwd.getpwuid(tarinfo.uid)[0] |
82 |
+ except KeyError: |
83 |
+ pass |
84 |
+ try: |
85 |
+ tarinfo.gname = grp.getgrgid(tarinfo.gid)[0] |
86 |
+ except KeyError: |
87 |
+ pass |
88 |
|
89 |
if stat.S_ISREG(lst.st_mode): |
90 |
if protect and protect(path): |