1 |
commit: 1d94992a2df2b5cc963c26c7978a899dc642deb1 |
2 |
Author: Sheng Yu <syu.os <AT> protonmail <DOT> com> |
3 |
AuthorDate: Thu Sep 1 14:44:55 2022 +0000 |
4 |
Commit: Michał Górny <mgorny <AT> gentoo <DOT> org> |
5 |
CommitDate: Fri Sep 9 10:15:58 2022 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=1d94992a |
7 |
|
8 |
Move all files into basename/DATA structure |
9 |
|
10 |
Signed-off-by: Sheng Yu <syu.os <AT> protonmail.com> |
11 |
Signed-off-by: Michał Górny <mgorny <AT> gentoo.org> |
12 |
|
13 |
lib/portage/binpkg.py | 8 +- |
14 |
lib/portage/dbapi/bintree.py | 2 +- |
15 |
lib/portage/gpkg.py | 201 +++++++++++++++++---------- |
16 |
lib/portage/tests/gpkg/test_gpkg_checksum.py | 21 +-- |
17 |
lib/portage/tests/gpkg/test_gpkg_gpg.py | 28 ++-- |
18 |
5 files changed, 158 insertions(+), 102 deletions(-) |
19 |
|
20 |
diff --git a/lib/portage/binpkg.py b/lib/portage/binpkg.py |
21 |
index ed2fda827..f3f149b14 100644 |
22 |
--- a/lib/portage/binpkg.py |
23 |
+++ b/lib/portage/binpkg.py |
24 |
@@ -17,8 +17,8 @@ def get_binpkg_format(binpkg_path): |
25 |
|
26 |
try: |
27 |
with open(binpkg_path, "rb") as binpkg_file: |
28 |
- header = binpkg_file.read(6) |
29 |
- if header == b"gpkg-1": |
30 |
+ header = binpkg_file.read(100) |
31 |
+ if b"/gpkg-1\x00" in header: |
32 |
file_format = "gpkg" |
33 |
else: |
34 |
binpkg_file.seek(-16, 2) |
35 |
@@ -32,7 +32,9 @@ def get_binpkg_format(binpkg_path): |
36 |
if file_format is None: |
37 |
try: |
38 |
with tarfile.open(binpkg_path) as gpkg_tar: |
39 |
- if "gpkg-1" in gpkg_tar.getnames(): |
40 |
+ if "gpkg-1" in [ |
41 |
+ f.split("/", maxsplit=1)[-1] for f in gpkg_tar.getnames() |
42 |
+ ]: |
43 |
file_format = "gpkg" |
44 |
except tarfile.TarError: |
45 |
pass |
46 |
|
47 |
diff --git a/lib/portage/dbapi/bintree.py b/lib/portage/dbapi/bintree.py |
48 |
index 0857ff21a..814e6627c 100644 |
49 |
--- a/lib/portage/dbapi/bintree.py |
50 |
+++ b/lib/portage/dbapi/bintree.py |
51 |
@@ -744,7 +744,7 @@ class binarytree: |
52 |
mytbz2.recompose_mem(portage.xpak.xpak_mem(mydata)) |
53 |
elif binpkg_format == "gpkg": |
54 |
mybinpkg = portage.gpkg.gpkg(self.settings, mycpv, update_path) |
55 |
- mybinpkg.update_metadata(mydata, newcpv=mynewcpv) |
56 |
+ mybinpkg.update_metadata(mydata, new_basename=mynewcpv) |
57 |
else: |
58 |
raise InvalidBinaryPackageFormat(binpkg_format) |
59 |
self.inject(mynewcpv, filename=update_path) |
60 |
|
61 |
diff --git a/lib/portage/gpkg.py b/lib/portage/gpkg.py |
62 |
index 644ff412b..5f8e19341 100644 |
63 |
--- a/lib/portage/gpkg.py |
64 |
+++ b/lib/portage/gpkg.py |
65 |
@@ -764,10 +764,10 @@ class gpkg: |
66 |
https://www.gentoo.org/glep/glep-0078.html |
67 |
""" |
68 |
|
69 |
- def __init__(self, settings, base_name=None, gpkg_file=None): |
70 |
+ def __init__(self, settings, basename=None, gpkg_file=None): |
71 |
""" |
72 |
gpkg class handle all gpkg operations for one package. |
73 |
- base_name is the package basename. |
74 |
+ basename is the package basename. |
75 |
gpkg_file should be exists file path for read or will create. |
76 |
""" |
77 |
self.settings = settings |
78 |
@@ -778,10 +778,16 @@ class gpkg: |
79 |
self.gpkg_file = _unicode_decode( |
80 |
gpkg_file, encoding=_encodings["fs"], errors="strict" |
81 |
) |
82 |
- self.base_name = base_name |
83 |
+ |
84 |
+ if basename is None: |
85 |
+ self.basename = None |
86 |
+ else: |
87 |
+ self.basename = basename.split("/", maxsplit=1)[-1] |
88 |
+ |
89 |
self.checksums = [] |
90 |
self.manifest_old = [] |
91 |
- signature_exist = None |
92 |
+ self.signature_exist = None |
93 |
+ self.prefix = None |
94 |
|
95 |
# Compression is the compression algorithm, if set to None will |
96 |
# not use compression. |
97 |
@@ -892,7 +898,9 @@ class gpkg: |
98 |
|
99 |
# Check gpkg and metadata |
100 |
with tarfile.open(mode="r", fileobj=container_file) as container: |
101 |
- if self.gpkg_version not in container.getnames(): |
102 |
+ if self.gpkg_version not in ( |
103 |
+ os.path.basename(f) for f in container.getnames() |
104 |
+ ): |
105 |
raise InvalidBinaryPackageFormat("Invalid gpkg file.") |
106 |
|
107 |
metadata_tarinfo, metadata_comp = self._get_inner_tarinfo( |
108 |
@@ -985,7 +993,7 @@ class gpkg: |
109 |
) |
110 |
|
111 |
# Long CPV |
112 |
- if len(self.base_name) >= 154: |
113 |
+ if len(self.basename) >= 154: |
114 |
container_tar_format = tarfile.GNU_FORMAT |
115 |
|
116 |
# gpkg container |
117 |
@@ -994,9 +1002,14 @@ class gpkg: |
118 |
) |
119 |
|
120 |
# gpkg version |
121 |
- gpkg_version_file = tarfile.TarInfo(self.gpkg_version) |
122 |
+ gpkg_version_file = tarfile.TarInfo( |
123 |
+ os.path.join(self.basename, self.gpkg_version) |
124 |
+ ) |
125 |
gpkg_version_file.mtime = datetime.utcnow().timestamp() |
126 |
container.addfile(gpkg_version_file) |
127 |
+ checksum_info = checksum_helper(self.settings) |
128 |
+ checksum_info.finish() |
129 |
+ self._record_checksum(checksum_info, gpkg_version_file) |
130 |
|
131 |
compression_cmd = self._get_compression_cmd() |
132 |
|
133 |
@@ -1059,16 +1072,19 @@ class gpkg: |
134 |
finally: |
135 |
image_tar.kill() |
136 |
|
137 |
- def update_metadata(self, metadata, newcpv=None): |
138 |
+ def update_metadata(self, metadata, new_basename=None): |
139 |
""" |
140 |
Update metadata in the gpkg file. |
141 |
""" |
142 |
self._verify_binpkg() |
143 |
self.checksums = [] |
144 |
- oldcpv = None |
145 |
+ old_basename = self.prefix |
146 |
|
147 |
- if newcpv: |
148 |
- oldcpv = self.base_name |
149 |
+ if new_basename is None: |
150 |
+ new_basename = old_basename |
151 |
+ else: |
152 |
+ new_basename = new_basename.split("/", maxsplit=1)[-1] |
153 |
+ self.basename = new_basename |
154 |
|
155 |
with open(self.gpkg_file, "rb") as container: |
156 |
container_tar_format = self._get_tar_format(container) |
157 |
@@ -1081,19 +1097,19 @@ class gpkg: |
158 |
name=tmp_gpkg_file_name, mode="w", format=container_tar_format |
159 |
) as container: |
160 |
# gpkg version |
161 |
- gpkg_version_file = tarfile.TarInfo(self.gpkg_version) |
162 |
+ gpkg_version_file = tarfile.TarInfo( |
163 |
+ os.path.join(new_basename, self.gpkg_version) |
164 |
+ ) |
165 |
gpkg_version_file.mtime = datetime.utcnow().timestamp() |
166 |
container.addfile(gpkg_version_file) |
167 |
+ checksum_info = checksum_helper(self.settings) |
168 |
+ checksum_info.finish() |
169 |
+ self._record_checksum(checksum_info, gpkg_version_file) |
170 |
|
171 |
compression_cmd = self._get_compression_cmd() |
172 |
|
173 |
# metadata |
174 |
- if newcpv: |
175 |
- self.base_name = newcpv |
176 |
- self._add_metadata(container, metadata, compression_cmd) |
177 |
- self.base_name = oldcpv |
178 |
- else: |
179 |
- self._add_metadata(container, metadata, compression_cmd) |
180 |
+ self._add_metadata(container, metadata, compression_cmd) |
181 |
|
182 |
# reuse other stuffs |
183 |
with tarfile.open(self.gpkg_file, "r") as container_old: |
184 |
@@ -1101,15 +1117,17 @@ class gpkg: |
185 |
|
186 |
for m in manifest_old: |
187 |
file_name_old = m[1] |
188 |
+ if os.path.basename(file_name_old) == self.gpkg_version: |
189 |
+ continue |
190 |
if os.path.basename(file_name_old).startswith("metadata"): |
191 |
continue |
192 |
- old_data_tarinfo = container_old.getmember(file_name_old) |
193 |
+ old_data_tarinfo = container_old.getmember( |
194 |
+ os.path.join(self.prefix, file_name_old) |
195 |
+ ) |
196 |
new_data_tarinfo = copy(old_data_tarinfo) |
197 |
- if newcpv: |
198 |
- m[1] = m[1].replace(oldcpv, newcpv, 1) |
199 |
- new_data_tarinfo.name = new_data_tarinfo.name.replace( |
200 |
- oldcpv, newcpv, 1 |
201 |
- ) |
202 |
+ new_data_tarinfo.name = new_data_tarinfo.name.replace( |
203 |
+ old_basename, new_basename, 1 |
204 |
+ ) |
205 |
container.addfile( |
206 |
new_data_tarinfo, container_old.extractfile(old_data_tarinfo) |
207 |
) |
208 |
@@ -1139,9 +1157,14 @@ class gpkg: |
209 |
name=tmp_gpkg_file_name, mode="w", format=container_tar_format |
210 |
) as container: |
211 |
# gpkg version |
212 |
- gpkg_version_file = tarfile.TarInfo(self.gpkg_version) |
213 |
+ gpkg_version_file = tarfile.TarInfo( |
214 |
+ os.path.join(self.prefix, self.gpkg_version) |
215 |
+ ) |
216 |
gpkg_version_file.mtime = datetime.utcnow().timestamp() |
217 |
container.addfile(gpkg_version_file) |
218 |
+ checksum_info = checksum_helper(self.settings) |
219 |
+ checksum_info.finish() |
220 |
+ self._record_checksum(checksum_info, gpkg_version_file) |
221 |
|
222 |
# reuse other stuffs |
223 |
with tarfile.open(self.gpkg_file, "r") as container_old: |
224 |
@@ -1150,9 +1173,13 @@ class gpkg: |
225 |
|
226 |
for m in manifest_old: |
227 |
file_name_old = m[1] |
228 |
+ if os.path.basename(file_name_old) == self.gpkg_version: |
229 |
+ continue |
230 |
if os.path.basename(file_name_old).endswith(".sig"): |
231 |
continue |
232 |
- old_data_tarinfo = container_old.getmember(file_name_old) |
233 |
+ old_data_tarinfo = container_old.getmember( |
234 |
+ os.path.join(self.prefix, file_name_old) |
235 |
+ ) |
236 |
new_data_tarinfo = copy(old_data_tarinfo) |
237 |
|
238 |
container.addfile( |
239 |
@@ -1261,7 +1288,7 @@ class gpkg: |
240 |
) |
241 |
|
242 |
# Long CPV |
243 |
- if len(self.base_name) >= 154: |
244 |
+ if len(self.basename) >= 154: |
245 |
container_tar_format = tarfile.GNU_FORMAT |
246 |
|
247 |
# GPKG container |
248 |
@@ -1270,9 +1297,14 @@ class gpkg: |
249 |
) |
250 |
|
251 |
# GPKG version |
252 |
- gpkg_version_file = tarfile.TarInfo(self.gpkg_version) |
253 |
+ gpkg_version_file = tarfile.TarInfo( |
254 |
+ os.path.join(self.basename, self.gpkg_version) |
255 |
+ ) |
256 |
gpkg_version_file.mtime = datetime.utcnow().timestamp() |
257 |
container.addfile(gpkg_version_file) |
258 |
+ checksum_info = checksum_helper(self.settings) |
259 |
+ checksum_info.finish() |
260 |
+ self._record_checksum(checksum_info, gpkg_version_file) |
261 |
|
262 |
compression_cmd = self._get_compression_cmd() |
263 |
# Metadata |
264 |
@@ -1404,12 +1436,15 @@ class gpkg: |
265 |
Record checksum result for the given file. |
266 |
Replace old checksum if already exists. |
267 |
""" |
268 |
+ |
269 |
+ # Remove prefix directory from the filename |
270 |
+ file_name = os.path.basename(tarinfo.name) |
271 |
+ |
272 |
for c in self.checksums: |
273 |
- if c[1] == tarinfo.name: |
274 |
+ if c[1] == file_name: |
275 |
self.checksums.remove(c) |
276 |
- break |
277 |
|
278 |
- checksum_record = ["DATA", tarinfo.name, str(tarinfo.size)] |
279 |
+ checksum_record = ["DATA", file_name, str(tarinfo.size)] |
280 |
|
281 |
for c in checksum_info.libs: |
282 |
checksum_record.append(c) |
283 |
@@ -1436,7 +1471,14 @@ class gpkg: |
284 |
manifest.seek(0) |
285 |
manifest.write(checksum_info.gpg_output) |
286 |
|
287 |
- manifest_tarinfo = tarfile.TarInfo("Manifest") |
288 |
+ if self.basename is not None: |
289 |
+ basename = self.basename |
290 |
+ elif self.prefix is not None: |
291 |
+ basename = self.prefix |
292 |
+ else: |
293 |
+ raise InvalidBinaryPackageFormat("No basename or prefix specified") |
294 |
+ |
295 |
+ manifest_tarinfo = tarfile.TarInfo(os.path.join(basename, "Manifest")) |
296 |
manifest_tarinfo.size = manifest.tell() |
297 |
manifest_tarinfo.mtime = datetime.utcnow().timestamp() |
298 |
manifest.seek(0) |
299 |
@@ -1523,10 +1565,30 @@ class gpkg: |
300 |
f"Cannot read tar file: {self.gpkg_file}" |
301 |
) |
302 |
|
303 |
- # Check gpkg header |
304 |
- if self.gpkg_version not in container_files: |
305 |
+ # Check if gpkg version file exists in any place |
306 |
+ if self.gpkg_version not in (os.path.basename(f) for f in container_files): |
307 |
raise InvalidBinaryPackageFormat(f"Invalid gpkg file: {self.gpkg_file}") |
308 |
|
309 |
+ # Check how many layers are in the container |
310 |
+ for f in container_files: |
311 |
+ if f.startswith("/"): |
312 |
+ raise InvalidBinaryPackageFormat( |
313 |
+ f"gpkg file structure mismatch '{f}' in {self.gpkg_file}" |
314 |
+ ) |
315 |
+ if f.count("/") != 1: |
316 |
+ raise InvalidBinaryPackageFormat( |
317 |
+ f"gpkg file structure mismatch '{f}' in {self.gpkg_file}" |
318 |
+ ) |
319 |
+ |
320 |
+ # Check if all directories are the same in the container |
321 |
+ prefix = os.path.commonpath(container_files) |
322 |
+ if not prefix: |
323 |
+ raise InvalidBinaryPackageFormat( |
324 |
+ f"gpkg file structure mismatch in {self.gpkg_file}, {str(container_files)}" |
325 |
+ ) |
326 |
+ |
327 |
+ gpkg_version_file = os.path.join(prefix, self.gpkg_version) |
328 |
+ |
329 |
# If any signature exists, we assume all files have signature. |
330 |
if any(f.endswith(".sig") for f in container_files): |
331 |
signature_exist = True |
332 |
@@ -1546,13 +1608,13 @@ class gpkg: |
333 |
|
334 |
# Add all files to check list |
335 |
unverified_files = container_files.copy() |
336 |
- unverified_files.remove(self.gpkg_version) |
337 |
|
338 |
# Check Manifest file |
339 |
- if "Manifest" not in unverified_files: |
340 |
+ manifest_filename = os.path.join(prefix, "Manifest") |
341 |
+ if manifest_filename not in unverified_files: |
342 |
raise MissingSignature(f"Manifest not found: {self.gpkg_file}") |
343 |
|
344 |
- manifest_file = container.extractfile("Manifest") |
345 |
+ manifest_file = container.extractfile(manifest_filename) |
346 |
manifest_data = manifest_file.read() |
347 |
manifest_file.close() |
348 |
|
349 |
@@ -1574,9 +1636,9 @@ class gpkg: |
350 |
raise |
351 |
|
352 |
manifest_data = checksum_info.gpg_output |
353 |
- unverified_files.remove("Manifest") |
354 |
+ unverified_files.remove(manifest_filename) |
355 |
else: |
356 |
- unverified_files.remove("Manifest") |
357 |
+ unverified_files.remove(manifest_filename) |
358 |
|
359 |
# Load manifest and create manifest check list |
360 |
manifest = self._load_manifest(manifest_data.decode("UTF-8")) |
361 |
@@ -1592,7 +1654,7 @@ class gpkg: |
362 |
# Find current file manifest record |
363 |
manifest_record = None |
364 |
for m in manifest: |
365 |
- if m[1] == f: |
366 |
+ if m[1] == os.path.basename(f): |
367 |
manifest_record = m |
368 |
|
369 |
if manifest_record is None: |
370 |
@@ -1625,6 +1687,9 @@ class gpkg: |
371 |
gpg_operation=checksum_helper.VERIFY, |
372 |
signature=signature, |
373 |
) |
374 |
+ elif f == gpkg_version_file: |
375 |
+ # gpkg version file is not signed |
376 |
+ checksum_info = checksum_helper(self.settings) |
377 |
else: |
378 |
raise MissingSignature( |
379 |
f"{f} signature not found in {self.gpkg_file}" |
380 |
@@ -1684,6 +1749,7 @@ class gpkg: |
381 |
# Save current Manifest for other operations. |
382 |
self.manifest_old = manifest.copy() |
383 |
self.signature_exist = signature_exist |
384 |
+ self.prefix = prefix |
385 |
|
386 |
def _generate_metadata_from_dir(self, metadata_dir): |
387 |
""" |
388 |
@@ -2017,9 +2083,13 @@ class gpkg: |
389 |
else: |
390 |
raise InvalidCompressionMethod(self.compression) |
391 |
|
392 |
- data_tarinfo = tarfile.TarInfo( |
393 |
- os.path.join(self.base_name, file_name + ".tar" + ext) |
394 |
- ) |
395 |
+ if self.basename: |
396 |
+ basename = self.basename |
397 |
+ elif self.prefix: |
398 |
+ basename = self.prefix |
399 |
+ else: |
400 |
+ raise InvalidBinaryPackageFormat("No basename or prefix specified") |
401 |
+ data_tarinfo = tarfile.TarInfo(os.path.join(basename, file_name + ".tar" + ext)) |
402 |
return data_tarinfo |
403 |
|
404 |
def _extract_filename_compression(self, file_name): |
405 |
@@ -2046,42 +2116,23 @@ class gpkg: |
406 |
if it fail, try any file that have same name as file_name, and |
407 |
return the first one. |
408 |
""" |
409 |
- if self.gpkg_version not in tar.getnames(): |
410 |
- raise InvalidBinaryPackageFormat("Invalid gpkg file.") |
411 |
+ if self.gpkg_version not in (os.path.basename(f) for f in tar.getnames()): |
412 |
+ raise InvalidBinaryPackageFormat(f"Invalid gpkg file") |
413 |
+ |
414 |
+ if self.basename and self.prefix and not self.prefix.startswith(self.basename): |
415 |
+ writemsg( |
416 |
+ colorize("WARN", f"Package basename mismatched, using {self.prefix}") |
417 |
+ ) |
418 |
|
419 |
- # Try get file with correct basename |
420 |
- inner_tarinfo = None |
421 |
- if self.base_name is None: |
422 |
- base_name = "" |
423 |
- else: |
424 |
- base_name = self.base_name |
425 |
all_files = tar.getmembers() |
426 |
for f in all_files: |
427 |
- if os.path.dirname(f.name) == base_name: |
428 |
- try: |
429 |
- f_name, f_comp = self._extract_filename_compression(f.name) |
430 |
- except InvalidCompressionMethod: |
431 |
- continue |
432 |
- |
433 |
- if f_name == file_name: |
434 |
- return f, f_comp |
435 |
+ try: |
436 |
+ f_name, f_comp = self._extract_filename_compression(f.name) |
437 |
+ except InvalidCompressionMethod: |
438 |
+ continue |
439 |
|
440 |
- # If failed, try get any file name matched |
441 |
- if inner_tarinfo is None: |
442 |
- for f in all_files: |
443 |
- try: |
444 |
- f_name, f_comp = self._extract_filename_compression(f.name) |
445 |
- except InvalidCompressionMethod: |
446 |
- continue |
447 |
- if f_name == file_name: |
448 |
- if self.base_name is not None: |
449 |
- writemsg( |
450 |
- colorize( |
451 |
- "WARN", "Package basename mismatched, using " + f.name |
452 |
- ) |
453 |
- ) |
454 |
- self.base_name_alt = os.path.dirname(f.name) |
455 |
- return f, f_comp |
456 |
+ if f_name == file_name: |
457 |
+ return f, f_comp |
458 |
|
459 |
# Not found |
460 |
raise FileNotFound(f"File Not found: {file_name}") |
461 |
|
462 |
diff --git a/lib/portage/tests/gpkg/test_gpkg_checksum.py b/lib/portage/tests/gpkg/test_gpkg_checksum.py |
463 |
index 5ccc099e6..be4b08661 100644 |
464 |
--- a/lib/portage/tests/gpkg/test_gpkg_checksum.py |
465 |
+++ b/lib/portage/tests/gpkg/test_gpkg_checksum.py |
466 |
@@ -47,7 +47,7 @@ class test_gpkg_checksum_case(TestCase): |
467 |
os.path.join(tmpdir, "test-2.gpkg.tar"), "w" |
468 |
) as tar_2: |
469 |
for f in tar_1.getmembers(): |
470 |
- if f.name != binpkg_1.gpkg_version: |
471 |
+ if f.name != os.path.join("test", binpkg_1.gpkg_version): |
472 |
tar_2.addfile(f, tar_1.extractfile(f)) |
473 |
|
474 |
binpkg_2 = gpkg(settings, "test", os.path.join(tmpdir, "test-2.gpkg.tar")) |
475 |
@@ -89,7 +89,7 @@ class test_gpkg_checksum_case(TestCase): |
476 |
os.path.join(tmpdir, "test-2.gpkg.tar"), "w" |
477 |
) as tar_2: |
478 |
for f in tar_1.getmembers(): |
479 |
- if f.name != "Manifest": |
480 |
+ if f.name != os.path.join("test", "Manifest"): |
481 |
tar_2.addfile(f, tar_1.extractfile(f)) |
482 |
|
483 |
binpkg_2 = gpkg(settings, "test", os.path.join(tmpdir, "test-2.gpkg.tar")) |
484 |
@@ -174,7 +174,7 @@ class test_gpkg_checksum_case(TestCase): |
485 |
) as tar_2: |
486 |
for f in tar_1.getmembers(): |
487 |
tar_2.addfile(f, tar_1.extractfile(f)) |
488 |
- data_tarinfo = tarfile.TarInfo("data2") |
489 |
+ data_tarinfo = tarfile.TarInfo(os.path.join("test", "data2")) |
490 |
data_tarinfo.size = len(data) |
491 |
data2 = io.BytesIO(data) |
492 |
tar_2.addfile(data_tarinfo, data2) |
493 |
@@ -217,7 +217,7 @@ class test_gpkg_checksum_case(TestCase): |
494 |
os.path.join(tmpdir, "test-2.gpkg.tar"), "w" |
495 |
) as tar_2: |
496 |
for f in tar_1.getmembers(): |
497 |
- if f.name == "Manifest": |
498 |
+ if f.name == os.path.join("test", "Manifest"): |
499 |
data = io.BytesIO(tar_1.extractfile(f).read()) |
500 |
data_view = data.getbuffer() |
501 |
data_view[-16:] = b"20a6d80ab0320fh9" |
502 |
@@ -306,7 +306,7 @@ class test_gpkg_checksum_case(TestCase): |
503 |
os.path.join(tmpdir, "test-2.gpkg.tar"), "w" |
504 |
) as tar_2: |
505 |
for f in tar_1.getmembers(): |
506 |
- if f.name == "Manifest": |
507 |
+ if f.name == os.path.join("test", "Manifest"): |
508 |
manifest = tar_1.extractfile(f).read() |
509 |
data = io.BytesIO(manifest) |
510 |
data.seek(io.SEEK_END) |
511 |
@@ -356,13 +356,18 @@ class test_gpkg_checksum_case(TestCase): |
512 |
os.path.join(tmpdir, "test-2.gpkg.tar"), "w" |
513 |
) as tar_2: |
514 |
for f in tar_1.getmembers(): |
515 |
- tar_2.addfile(f, tar_1.extractfile(f)) |
516 |
- tar_2.addfile(f, tar_1.extractfile(f)) |
517 |
+ if "image" in f.name: |
518 |
+ data = tar_1.extractfile(f).read() |
519 |
+ data = data + b"1234" |
520 |
+ f.size = len(data) |
521 |
+ tar_2.addfile(f, io.BytesIO(data)) |
522 |
+ else: |
523 |
+ tar_2.addfile(f, tar_1.extractfile(f)) |
524 |
|
525 |
binpkg_2 = gpkg(settings, "test", os.path.join(tmpdir, "test-2.gpkg.tar")) |
526 |
|
527 |
self.assertRaises( |
528 |
- InvalidBinaryPackageFormat, |
529 |
+ DigestException, |
530 |
binpkg_2.decompress, |
531 |
os.path.join(tmpdir, "test"), |
532 |
) |
533 |
|
534 |
diff --git a/lib/portage/tests/gpkg/test_gpkg_gpg.py b/lib/portage/tests/gpkg/test_gpkg_gpg.py |
535 |
index 9a9b7ef23..442764d7e 100644 |
536 |
--- a/lib/portage/tests/gpkg/test_gpkg_gpg.py |
537 |
+++ b/lib/portage/tests/gpkg/test_gpkg_gpg.py |
538 |
@@ -46,7 +46,7 @@ class test_gpkg_gpg_case(TestCase): |
539 |
os.path.join(tmpdir, "test-2.gpkg.tar"), "w" |
540 |
) as tar_2: |
541 |
for f in tar_1.getmembers(): |
542 |
- if f.name == "Manifest": |
543 |
+ if f.name == os.path.join("test", "Manifest"): |
544 |
manifest = tar_1.extractfile(f).read().decode("UTF-8") |
545 |
manifest = manifest.replace( |
546 |
"-----BEGIN PGP SIGNATURE-----", "" |
547 |
@@ -116,11 +116,19 @@ class test_gpkg_gpg_case(TestCase): |
548 |
playground.cleanup() |
549 |
|
550 |
def test_gpkg_ignore_signature(self): |
551 |
+ gpg_test_path = os.environ["PORTAGE_GNUPGHOME"] |
552 |
+ |
553 |
playground = ResolverPlayground( |
554 |
user_config={ |
555 |
"make.conf": ( |
556 |
'FEATURES="${FEATURES} binpkg-signing ' 'binpkg-ignore-signature"', |
557 |
'BINPKG_FORMAT="gpkg"', |
558 |
+ f'BINPKG_GPG_SIGNING_BASE_COMMAND="flock {gpg_test_path}/portage-binpkg-gpg.lock /usr/bin/gpg --sign --armor --batch --no-tty --yes --pinentry-mode loopback --passphrase GentooTest [PORTAGE_CONFIG]"', |
559 |
+ 'BINPKG_GPG_SIGNING_DIGEST="SHA512"', |
560 |
+ f'BINPKG_GPG_SIGNING_GPG_HOME="{gpg_test_path}"', |
561 |
+ 'BINPKG_GPG_SIGNING_KEY="0x8812797DDF1DD192"', |
562 |
+ 'BINPKG_GPG_VERIFY_BASE_COMMAND="/usr/bin/gpg --verify --batch --no-tty --yes --no-auto-check-trustdb --status-fd 2 [PORTAGE_CONFIG] [SIGNATURE]"', |
563 |
+ f'BINPKG_GPG_VERIFY_GPG_HOME="{gpg_test_path}"', |
564 |
), |
565 |
} |
566 |
) |
567 |
@@ -140,17 +148,7 @@ class test_gpkg_gpg_case(TestCase): |
568 |
binpkg_1 = gpkg(settings, "test", os.path.join(tmpdir, "test-1.gpkg.tar")) |
569 |
binpkg_1.compress(orig_full_path, {}) |
570 |
|
571 |
- with tarfile.open(os.path.join(tmpdir, "test-1.gpkg.tar"), "r") as tar_1: |
572 |
- with tarfile.open( |
573 |
- os.path.join(tmpdir, "test-2.gpkg.tar"), "w" |
574 |
- ) as tar_2: |
575 |
- for f in tar_1.getmembers(): |
576 |
- if f.name == "Manifest.sig": |
577 |
- pass |
578 |
- else: |
579 |
- tar_2.addfile(f, tar_1.extractfile(f)) |
580 |
- |
581 |
- binpkg_2 = gpkg(settings, "test", os.path.join(tmpdir, "test-2.gpkg.tar")) |
582 |
+ binpkg_2 = gpkg(settings, "test", os.path.join(tmpdir, "test-1.gpkg.tar")) |
583 |
binpkg_2.decompress(os.path.join(tmpdir, "test")) |
584 |
finally: |
585 |
shutil.rmtree(tmpdir) |
586 |
@@ -230,7 +228,7 @@ class test_gpkg_gpg_case(TestCase): |
587 |
os.path.join(tmpdir, "test-2.gpkg.tar"), "w" |
588 |
) as tar_2: |
589 |
for f in tar_1.getmembers(): |
590 |
- if f.name == "Manifest": |
591 |
+ if f.name == os.path.join("test", "Manifest"): |
592 |
sig = b""" |
593 |
-----BEGIN PGP SIGNED MESSAGE----- |
594 |
Hash: SHA512 |
595 |
@@ -281,7 +279,7 @@ qGAN3VUF+8EsdcsV781H0F86PANhyBgEYTGDrnItTGe3/vAPjCo= |
596 |
'BINPKG_GPG_SIGNING_DIGEST="SHA512"', |
597 |
f'BINPKG_GPG_SIGNING_GPG_HOME="{gpg_test_path}"', |
598 |
'BINPKG_GPG_SIGNING_KEY="0x8812797DDF1DD192"', |
599 |
- 'BINPKG_GPG_VERIFY_BASE_COMMAND="/usr/bin/gpg --verify --batch --no-tty --yes --no-auto-check-trustdb --status-fd 1 [PORTAGE_CONFIG] [SIGNATURE]"', |
600 |
+ 'BINPKG_GPG_VERIFY_BASE_COMMAND="/usr/bin/gpg --verify --batch --no-tty --yes --no-auto-check-trustdb --status-fd 2 [PORTAGE_CONFIG] [SIGNATURE]"', |
601 |
f'BINPKG_GPG_VERIFY_GPG_HOME="{gpg_test_path}"', |
602 |
), |
603 |
} |
604 |
@@ -341,7 +339,7 @@ qGAN3VUF+8EsdcsV781H0F86PANhyBgEYTGDrnItTGe3/vAPjCo= |
605 |
os.path.join(tmpdir, "test-2.gpkg.tar"), "w" |
606 |
) as tar_2: |
607 |
for f in tar_1.getmembers(): |
608 |
- if f.name == "Manifest": |
609 |
+ if f.name == os.path.join("test", "Manifest"): |
610 |
sig = b""" |
611 |
-----BEGIN PGP SIGNED MESSAGE----- |
612 |
Hash: SHA256 |