1 |
commit: b24a484ab190af9c9b96b9ef01837aded845fb54 |
2 |
Author: Zac Medico <zmedico <AT> gentoo <DOT> org> |
3 |
AuthorDate: Mon Nov 18 01:32:38 2019 +0000 |
4 |
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> |
5 |
CommitDate: Mon Nov 18 01:41:27 2019 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=b24a484a |
7 |
|
8 |
dblink: add quickpkg method |
9 |
|
10 |
Bug: https://bugs.gentoo.org/699986 |
11 |
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org> |
12 |
|
13 |
bin/quickpkg | 34 ++++-------------------------- |
14 |
lib/portage/dbapi/vartree.py | 50 ++++++++++++++++++++++++++++++++++++++++++++ |
15 |
2 files changed, 54 insertions(+), 30 deletions(-) |
16 |
|
17 |
diff --git a/bin/quickpkg b/bin/quickpkg |
18 |
index c28a3e382..df8c1a8e8 100755 |
19 |
--- a/bin/quickpkg |
20 |
+++ b/bin/quickpkg |
21 |
@@ -10,7 +10,6 @@ import math |
22 |
import signal |
23 |
import subprocess |
24 |
import sys |
25 |
-import tarfile |
26 |
|
27 |
from os import path as osp |
28 |
if osp.isfile(osp.join(osp.dirname(osp.dirname(osp.realpath(__file__))), ".portage_not_installed")): |
29 |
@@ -23,10 +22,8 @@ from portage.dbapi.dep_expand import dep_expand |
30 |
from portage.dep import Atom, use_reduce |
31 |
from portage.exception import (AmbiguousPackageName, InvalidAtom, InvalidData, |
32 |
InvalidDependString, PackageSetNotFound, PermissionDenied) |
33 |
-from portage.util import ConfigProtect, ensure_dirs, shlex_split, varexpand, _xattr |
34 |
+from portage.util import ensure_dirs, shlex_split, varexpand, _xattr |
35 |
xattr = _xattr.xattr |
36 |
-from portage.dbapi.vartree import dblink, tar_contents |
37 |
-from portage.checksum import perform_md5 |
38 |
from portage._sets import load_default_config, SETPREFIX |
39 |
from portage.process import find_binary |
40 |
from portage.util.compression_probe import _compressors |
41 |
@@ -35,13 +32,11 @@ from portage.util._eventloop.global_event_loop import global_event_loop |
42 |
|
43 |
def quickpkg_atom(options, infos, arg, eout): |
44 |
settings = portage.settings |
45 |
- root = portage.settings['ROOT'] |
46 |
eroot = portage.settings['EROOT'] |
47 |
trees = portage.db[eroot] |
48 |
vartree = trees["vartree"] |
49 |
vardb = vartree.dbapi |
50 |
bintree = trees["bintree"] |
51 |
- xattrs = 'xattr' in settings.features |
52 |
|
53 |
include_config = options.include_config == "y" |
54 |
include_unmodified_config = options.include_unmodified_config == "y" |
55 |
@@ -104,26 +99,6 @@ def quickpkg_atom(options, infos, arg, eout): |
56 |
eout.ewarn("%s: it might not be legal to redistribute this." % cpv) |
57 |
eout.ebegin("Building package for %s" % cpv) |
58 |
pkgs_for_arg += 1 |
59 |
- contents = dblnk.getcontents() |
60 |
- protect = None |
61 |
- if not include_config: |
62 |
- confprot = ConfigProtect(eroot, |
63 |
- shlex_split(settings.get("CONFIG_PROTECT", "")), |
64 |
- shlex_split(settings.get("CONFIG_PROTECT_MASK", "")), |
65 |
- case_insensitive=("case-insensitive-fs" |
66 |
- in settings.features)) |
67 |
- def protect(filename): |
68 |
- if not confprot.isprotected(filename): |
69 |
- return False |
70 |
- if include_unmodified_config: |
71 |
- file_data = contents[filename] |
72 |
- if file_data[0] == "obj": |
73 |
- orig_md5 = file_data[2].lower() |
74 |
- cur_md5 = perform_md5(filename, calc_prelink=1) |
75 |
- if orig_md5 == cur_md5: |
76 |
- return False |
77 |
- excluded_config_files.append(filename) |
78 |
- return True |
79 |
existing_metadata = dict(zip(fix_metadata_keys, |
80 |
vardb.aux_get(cpv, fix_metadata_keys))) |
81 |
category, pf = portage.catsplit(cpv) |
82 |
@@ -167,10 +142,9 @@ def quickpkg_atom(options, infos, arg, eout): |
83 |
cmd = [x for x in cmd if x != ""] |
84 |
with open(binpkg_tmpfile, "wb") as fobj: |
85 |
proc = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=fobj) |
86 |
- # The tarfile module will write pax headers holding the |
87 |
- # xattrs only if PAX_FORMAT is specified here. |
88 |
- with tarfile.open(mode="w|",format=tarfile.PAX_FORMAT if xattrs else tarfile.DEFAULT_FORMAT, fileobj=proc.stdin) as tar: |
89 |
- tar_contents(contents, root, tar, protect=protect, xattrs=xattrs) |
90 |
+ excluded_config_files = dblnk.quickpkg(proc.stdin, |
91 |
+ include_config=include_config, |
92 |
+ include_unmodified_config=include_unmodified_config) |
93 |
proc.stdin.close() |
94 |
if proc.wait() != os.EX_OK: |
95 |
eout.eend(1) |
96 |
|
97 |
diff --git a/lib/portage/dbapi/vartree.py b/lib/portage/dbapi/vartree.py |
98 |
index fa1e1523c..603d58015 100644 |
99 |
--- a/lib/portage/dbapi/vartree.py |
100 |
+++ b/lib/portage/dbapi/vartree.py |
101 |
@@ -1883,6 +1883,56 @@ class dblink(object): |
102 |
self.contentscache = pkgfiles |
103 |
return pkgfiles |
104 |
|
105 |
+ def quickpkg(self, output_file, include_config=False, include_unmodified_config=False): |
106 |
+ """ |
107 |
+ Create a tar file appropriate for use by quickpkg. |
108 |
+ |
109 |
+ @param output_file: Write binary tar stream to file. |
110 |
+ @type output_file: file |
111 |
+ @param include_config: Include all files protected by CONFIG_PROTECT |
112 |
+ (as a security precaution, default is False). |
113 |
+ @type include_config: bool |
114 |
+ @param include_config: Include files protected by CONFIG_PROTECT that |
115 |
+ have not been modified since installation (as a security precaution, |
116 |
+ default is False). |
117 |
+ @type include_config: bool |
118 |
+ @rtype: list |
119 |
+ @return: Paths of protected configuration files which have been omitted. |
120 |
+ """ |
121 |
+ settings = self.settings |
122 |
+ cpv = self.mycpv |
123 |
+ xattrs = 'xattr' in settings.features |
124 |
+ contents = self.getcontents() |
125 |
+ excluded_config_files = [] |
126 |
+ protect = None |
127 |
+ |
128 |
+ if not include_config: |
129 |
+ confprot = ConfigProtect(settings['EROOT'], |
130 |
+ portage.util.shlex_split(settings.get('CONFIG_PROTECT', '')), |
131 |
+ portage.util.shlex_split(settings.get('CONFIG_PROTECT_MASK', '')), |
132 |
+ case_insensitive=('case-insensitive-fs' in settings.features)) |
133 |
+ |
134 |
+ def protect(filename): |
135 |
+ if not confprot.isprotected(filename): |
136 |
+ return False |
137 |
+ if include_unmodified_config: |
138 |
+ file_data = contents[filename] |
139 |
+ if file_data[0] == 'obj': |
140 |
+ orig_md5 = file_data[2].lower() |
141 |
+ cur_md5 = perform_md5(filename, calc_prelink=1) |
142 |
+ if orig_md5 == cur_md5: |
143 |
+ return False |
144 |
+ excluded_config_files.append(filename) |
145 |
+ return True |
146 |
+ |
147 |
+ # The tarfile module will write pax headers holding the |
148 |
+ # xattrs only if PAX_FORMAT is specified here. |
149 |
+ with tarfile.open(fileobj=output_file, mode='w|', |
150 |
+ format=tarfile.PAX_FORMAT if xattrs else tarfile.DEFAULT_FORMAT) as tar: |
151 |
+ tar_contents(contents, settings['ROOT'], tar, protect=protect, xattrs=xattrs) |
152 |
+ |
153 |
+ return excluded_config_files |
154 |
+ |
155 |
def _prune_plib_registry(self, unmerge=False, |
156 |
needed=None, preserve_paths=None): |
157 |
# remove preserved libraries that don't have any consumers left |