Gentoo Archives: gentoo-portage-dev

From: Zac Medico <zmedico@g.o>
To: gentoo-portage-dev@l.g.o
Cc: Zac Medico <zmedico@g.o>
Subject: [gentoo-portage-dev] [PATCH v2] quickpkg: support FEATURES=xattr (bug 550006)
Date: Sat, 23 May 2015 07:35:48
Message-Id: 1432366522-23899-1-git-send-email-zmedico@gentoo.org
In Reply to: [gentoo-portage-dev] [PATCH] quickpkg: support FEATURES=xattr (bug 550006) by Zac Medico
1 The xattrs are preserved in pax headers, in the same way that GNU tar
2 preserves them.
3
4 X-Gentoo-Bug: 550006
5 X-Gentoo-Bug-url: https://bugs.gentoo.org/show_bug.cgi?id=550006
6 ---
7 [PATCH v2] adds absolute_import in portage.util.xattr (py 2.x compat)
8
9 bin/quickpkg | 16 ++++++++++++++--
10 pym/portage/dbapi/vartree.py | 18 +++++++++++++++---
11 pym/portage/util/xattr.py | 20 ++++++++++++++++++++
12 3 files changed, 49 insertions(+), 5 deletions(-)
13 create mode 100644 pym/portage/util/xattr.py
14
15 diff --git a/bin/quickpkg b/bin/quickpkg
16 index 8b71c3e..726abff 100755
17 --- a/bin/quickpkg
18 +++ b/bin/quickpkg
19 @@ -22,6 +22,7 @@ from portage.dep import Atom, use_reduce
20 from portage.exception import (AmbiguousPackageName, InvalidAtom, InvalidData,
21 InvalidDependString, PackageSetNotFound, PermissionDenied)
22 from portage.util import ConfigProtect, ensure_dirs, shlex_split
23 +import portage.util.xattr as _xattr
24 from portage.dbapi.vartree import dblink, tar_contents
25 from portage.checksum import perform_md5
26 from portage._sets import load_default_config, SETPREFIX
27 @@ -35,6 +36,7 @@ def quickpkg_atom(options, infos, arg, eout):
28 vartree = trees["vartree"]
29 vardb = vartree.dbapi
30 bintree = trees["bintree"]
31 + xattr = 'xattr' in settings.features
32
33 include_config = options.include_config == "y"
34 include_unmodified_config = options.include_unmodified_config == "y"
35 @@ -132,8 +134,11 @@ def quickpkg_atom(options, infos, arg, eout):
36 binpkg_tmpfile = os.path.join(bintree.pkgdir,
37 cpv + ".tbz2." + str(os.getpid()))
38 ensure_dirs(os.path.dirname(binpkg_tmpfile))
39 - tar = tarfile.open(binpkg_tmpfile, "w:bz2")
40 - tar_contents(contents, root, tar, protect=protect)
41 + # The tarfile module will write pax headers holding the
42 + # xattrs only if PAX_FORMAT is specified here.
43 + tar = tarfile.open(binpkg_tmpfile, "w:bz2",
44 + format=tarfile.PAX_FORMAT if xattr else tarfile.DEFAULT_FORMAT)
45 + tar_contents(contents, root, tar, protect=protect, xattr=xattr)
46 tar.close()
47 xpak.tbz2(binpkg_tmpfile).recompose_mem(xpdata)
48 finally:
49 @@ -233,6 +238,13 @@ def quickpkg_main(options, args, eout):
50 eout.eerror("No write access to '%s'" % bintree.pkgdir)
51 return errno.EACCES
52
53 + if 'xattr' in portage.settings.features and not hasattr(_xattr, 'getxattr'):
54 + eout.eerror("No xattr support library was found, "
55 + "so xattrs will not be preserved!")
56 + portage.settings.unlock()
57 + portage.settings.features.remove('xattr')
58 + portage.settings.lock()
59 +
60 infos = {}
61 infos["successes"] = []
62 infos["missing"] = []
63 diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py
64 index a2fb325..62d880e 100644
65 --- a/pym/portage/dbapi/vartree.py
66 +++ b/pym/portage/dbapi/vartree.py
67 @@ -35,6 +35,7 @@ portage.proxy.lazyimport.lazyimport(globals(),
68 'portage.util.movefile:movefile',
69 'portage.util.path:first_existing,iter_parents',
70 'portage.util.writeable_check:get_ro_checker',
71 + 'portage.util:xattr@_xattr',
72 'portage.util._dyn_libs.PreservedLibsRegistry:PreservedLibsRegistry',
73 'portage.util._dyn_libs.LinkageMapELF:LinkageMapELF@LinkageMap',
74 'portage.util._async.SchedulerInterface:SchedulerInterface',
75 @@ -5266,7 +5267,8 @@ def write_contents(contents, root, f):
76 line = "%s %s\n" % (entry_type, relative_filename)
77 f.write(line)
78
79 -def tar_contents(contents, root, tar, protect=None, onProgress=None):
80 +def tar_contents(contents, root, tar, protect=None, onProgress=None,
81 + xattr=False):
82 os = _os_merge
83 encoding = _encodings['merge']
84
85 @@ -5384,9 +5386,19 @@ def tar_contents(contents, root, tar, protect=None, onProgress=None):
86 tar.addfile(tarinfo, f)
87 f.close()
88 else:
89 - with open(_unicode_encode(path,
90 + path_bytes = _unicode_encode(path,
91 encoding=encoding,
92 - errors='strict'), 'rb') as f:
93 + errors='strict')
94 +
95 + if xattr:
96 + # Compatible with GNU tar, which saves the xattrs
97 + # under the SCHILY.xattr namespace.
98 + for k in _xattr.listxattr(path_bytes):
99 + tarinfo.pax_headers['SCHILY.xattr.' +
100 + _unicode_decode(k)] = _unicode_decode(
101 + _xattr.getxattr(path_bytes, _unicode_encode(k)))
102 +
103 + with open(path_bytes, 'rb') as f:
104 tar.addfile(tarinfo, f)
105
106 else:
107 diff --git a/pym/portage/util/xattr.py b/pym/portage/util/xattr.py
108 new file mode 100644
109 index 0000000..b8c4620
110 --- /dev/null
111 +++ b/pym/portage/util/xattr.py
112 @@ -0,0 +1,20 @@
113 +# Copyright 2015 Gentoo Foundation
114 +# Distributed under the terms of the GNU General Public License v2
115 +
116 +from __future__ import absolute_import
117 +
118 +import os as _os
119 +
120 +if hasattr(_os, "getxattr"):
121 + getxattr = _os.getxattr
122 + listxattr = _os.listxattr
123 + setxattr = _os.setxattr
124 +else:
125 + try:
126 + import xattr as _xattr
127 + except ImportError:
128 + pass
129 + else:
130 + getxattr = _xattr.get
131 + listxattr = _xattr.list
132 + setxattr = _xattr.set
133 --
134 2.3.5