Gentoo Archives: gentoo-commits

From: Zac Medico <zmedico@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:master commit in: lib/portage/binrepo/, lib/_emerge/, lib/portage/dbapi/, man/
Date: Tue, 08 Sep 2020 02:35:13
Message-Id: 1599529088.5ebc8a249b08318da5a2ca89cee2eed604f7e639.zmedico@gentoo
1 commit: 5ebc8a249b08318da5a2ca89cee2eed604f7e639
2 Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
3 AuthorDate: Mon Sep 7 00:13:13 2020 +0000
4 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
5 CommitDate: Tue Sep 8 01:38:08 2020 +0000
6 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=5ebc8a24
7
8 binrepos.conf: support fetchcommand customization (bug 668302)
9
10 Support customization of fetchcommand and resumecommand in
11 binrepos.conf, allowing customized authentication mechanisms for
12 each repository.
13
14 Bug: https://bugs.gentoo.org/668302
15 Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
16
17 lib/_emerge/BinpkgFetcher.py | 29 +++++++++++++++++++----------
18 lib/portage/binrepo/config.py | 2 ++
19 lib/portage/dbapi/bintree.py | 34 +++++++++++++++++++++++++---------
20 man/portage.5 | 14 ++++++++++++++
21 4 files changed, 60 insertions(+), 19 deletions(-)
22
23 diff --git a/lib/_emerge/BinpkgFetcher.py b/lib/_emerge/BinpkgFetcher.py
24 index 218d4d2ab..9a96bde28 100644
25 --- a/lib/_emerge/BinpkgFetcher.py
26 +++ b/lib/_emerge/BinpkgFetcher.py
27 @@ -96,14 +96,17 @@ class _BinpkgFetcherProcess(SpawnProcess):
28
29 # urljoin doesn't work correctly with
30 # unrecognized protocols like sftp
31 + fetchcommand = None
32 + resumecommand = None
33 if bintree._remote_has_index:
34 - instance_key = bintree.dbapi._instance_key(pkg.cpv)
35 - rel_uri = bintree._remotepkgs[instance_key].get("PATH")
36 + remote_metadata = bintree._remotepkgs[bintree.dbapi._instance_key(pkg.cpv)]
37 + rel_uri = remote_metadata.get("PATH")
38 if not rel_uri:
39 rel_uri = pkg.cpv + ".tbz2"
40 - remote_base_uri = bintree._remotepkgs[
41 - instance_key]["BASE_URI"]
42 + remote_base_uri = remote_metadata["BASE_URI"]
43 uri = remote_base_uri.rstrip("/") + "/" + rel_uri.lstrip("/")
44 + fetchcommand = remote_metadata.get('FETCHCOMMAND')
45 + resumecommand = remote_metadata.get('RESUMECOMMAND')
46 else:
47 uri = settings["PORTAGE_BINHOST"].rstrip("/") + \
48 "/" + pkg.pf + ".tbz2"
49 @@ -114,13 +117,19 @@ class _BinpkgFetcherProcess(SpawnProcess):
50 self._async_wait()
51 return
52
53 - protocol = urllib_parse_urlparse(uri)[0]
54 - fcmd_prefix = "FETCHCOMMAND"
55 + fcmd = None
56 if resume:
57 - fcmd_prefix = "RESUMECOMMAND"
58 - fcmd = settings.get(fcmd_prefix + "_" + protocol.upper())
59 - if not fcmd:
60 - fcmd = settings.get(fcmd_prefix)
61 + fcmd = resumecommand
62 + else:
63 + fcmd = fetchcommand
64 + if fcmd is None:
65 + protocol = urllib_parse_urlparse(uri)[0]
66 + fcmd_prefix = "FETCHCOMMAND"
67 + if resume:
68 + fcmd_prefix = "RESUMECOMMAND"
69 + fcmd = settings.get(fcmd_prefix + "_" + protocol.upper())
70 + if not fcmd:
71 + fcmd = settings.get(fcmd_prefix)
72
73 fcmd_vars = {
74 "DISTDIR" : os.path.dirname(pkg_path),
75
76 diff --git a/lib/portage/binrepo/config.py b/lib/portage/binrepo/config.py
77 index a4bce9073..6ba1a3e9f 100644
78 --- a/lib/portage/binrepo/config.py
79 +++ b/lib/portage/binrepo/config.py
80 @@ -15,7 +15,9 @@ class BinRepoConfig:
81 __slots__ = (
82 'name',
83 'name_fallback',
84 + 'fetchcommand',
85 'priority',
86 + 'resumecommand',
87 'sync_uri',
88 )
89 def __init__(self, opts):
90
91 diff --git a/lib/portage/dbapi/bintree.py b/lib/portage/dbapi/bintree.py
92 index 97018db6e..e4393e06d 100644
93 --- a/lib/portage/dbapi/bintree.py
94 +++ b/lib/portage/dbapi/bintree.py
95 @@ -382,10 +382,10 @@ class binarytree:
96 self._pkgindex_keys.update(["CPV", "SIZE"])
97 self._pkgindex_aux_keys = \
98 ["BASE_URI", "BDEPEND", "BUILD_ID", "BUILD_TIME", "CHOST",
99 - "DEFINED_PHASES", "DEPEND", "DESCRIPTION", "EAPI",
100 + "DEFINED_PHASES", "DEPEND", "DESCRIPTION", "EAPI", "FETCHCOMMAND",
101 "IUSE", "KEYWORDS", "LICENSE", "PDEPEND",
102 "PKGINDEX_URI", "PROPERTIES", "PROVIDES",
103 - "RDEPEND", "repository", "REQUIRES", "RESTRICT",
104 + "RDEPEND", "repository", "REQUIRES", "RESTRICT", "RESUMECOMMAND",
105 "SIZE", "SLOT", "USE"]
106 self._pkgindex_aux_keys = list(self._pkgindex_aux_keys)
107 self._pkgindex_use_evaluated_keys = \
108 @@ -979,7 +979,7 @@ class binarytree:
109
110 # Don't use urlopen for https, unless
111 # PEP 476 is supported (bug #469888).
112 - if parsed_url.scheme not in ('https',) or _have_pep_476():
113 + if repo.fetchcommand is None and (parsed_url.scheme not in ('https',) or _have_pep_476()):
114 try:
115 f = _urlopen(url, if_modified_since=local_timestamp, proxies=proxies)
116 if hasattr(f, 'headers') and f.headers.get('timestamp', ''):
117 @@ -1004,7 +1004,7 @@ class binarytree:
118
119 path = parsed_url.path.rstrip("/") + "/Packages"
120
121 - if parsed_url.scheme == 'ssh':
122 + if repo.fetchcommand is None and parsed_url.scheme == 'ssh':
123 # Use a pipe so that we can terminate the download
124 # early if we detect that the TIMESTAMP header
125 # matches that of the cached Packages file.
126 @@ -1023,12 +1023,15 @@ class binarytree:
127 stdout=subprocess.PIPE)
128 f = proc.stdout
129 else:
130 - setting = 'FETCHCOMMAND_' + parsed_url.scheme.upper()
131 - fcmd = self.settings.get(setting)
132 - if not fcmd:
133 - fcmd = self.settings.get('FETCHCOMMAND')
134 + if repo.fetchcommand is None:
135 + setting = 'FETCHCOMMAND_' + parsed_url.scheme.upper()
136 + fcmd = self.settings.get(setting)
137 if not fcmd:
138 - raise EnvironmentError("FETCHCOMMAND is unset")
139 + fcmd = self.settings.get('FETCHCOMMAND')
140 + if not fcmd:
141 + raise EnvironmentError("FETCHCOMMAND is unset")
142 + else:
143 + fcmd = repo.fetchcommand
144
145 fd, tmp_filename = tempfile.mkstemp()
146 tmp_dirname, tmp_basename = os.path.split(tmp_filename)
147 @@ -1142,6 +1145,19 @@ class binarytree:
148 d["CPV"] = cpv
149 d["BASE_URI"] = remote_base_uri
150 d["PKGINDEX_URI"] = url
151 + # FETCHCOMMAND and RESUMECOMMAND may be specified
152 + # by binrepos.conf, and otherwise ensure that they
153 + # do not propagate from the Packages index since
154 + # it may be unsafe to execute remotely specified
155 + # commands.
156 + if repo.fetchcommand is None:
157 + d.pop('FETCHCOMMAND', None)
158 + else:
159 + d['FETCHCOMMAND'] = repo.fetchcommand
160 + if repo.resumecommand is None:
161 + d.pop('RESUMECOMMAND', None)
162 + else:
163 + d['RESUMECOMMAND'] = repo.resumecommand
164 self._remotepkgs[self.dbapi._instance_key(cpv)] = d
165 self.dbapi.cpv_inject(cpv)
166
167
168 diff --git a/man/portage.5 b/man/portage.5
169 index 4f183654c..82dd8a509 100644
170 --- a/man/portage.5
171 +++ b/man/portage.5
172 @@ -634,6 +634,20 @@ is intended to be used as a replacement for the \fBmake.conf\fR(5)
173 \- attributes are specified in "${attribute} = ${value}" format
174 .fi
175
176 +.RS
177 +.I Attributes supported in DEFAULT section:
178 +.RS
179 +.TP
180 +.B fetchcommand
181 +Specifies a \fBFETCHCOMMAND\fR used to fetch files from a repository,
182 +overriding the value from \fBmake.conf\fR(5).
183 +.TP
184 +.B resumecommand
185 +Specifies a \fBRESUMECOMMAND\fR used to fetch files from a repository,
186 +overriding the value from \fBmake.conf\fR(5).
187 +.RE
188 +.RE
189 +
190 .RS
191 .I Attributes supported in sections of repositories:
192 .RS