1 |
commit: 5f256ab11e5510f98d7951ac9770948e00c36ed5 |
2 |
Author: Sheng Yu <syu.os <AT> protonmail <DOT> com> |
3 |
AuthorDate: Wed Nov 2 19:05:29 2022 +0000 |
4 |
Commit: Sam James <sam <AT> gentoo <DOT> org> |
5 |
CommitDate: Wed Nov 2 22:58:15 2022 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=5f256ab1 |
7 |
|
8 |
Unconditionally update first level of dir name in binpkgs |
9 |
|
10 |
Enabling / disabling binpkg-multi-instance while doing metadata move / |
11 |
update may cause binary package structure mismatch. |
12 |
|
13 |
This will unconditional replace the first level name (cpv) in the |
14 |
package. |
15 |
|
16 |
Closes: https://bugs.gentoo.org/877271 |
17 |
Signed-off-by: Sheng Yu <syu.os <AT> protonmail.com> |
18 |
Closes: https://github.com/gentoo/portage/pull/929 |
19 |
Signed-off-by: Sam James <sam <AT> gentoo.org> |
20 |
|
21 |
lib/portage/gpkg.py | 36 +++++++++++++++++++++++++++++++++--- |
22 |
1 file changed, 33 insertions(+), 3 deletions(-) |
23 |
|
24 |
diff --git a/lib/portage/gpkg.py b/lib/portage/gpkg.py |
25 |
index 5a8c16186..3d2aa4223 100644 |
26 |
--- a/lib/portage/gpkg.py |
27 |
+++ b/lib/portage/gpkg.py |
28 |
@@ -1048,6 +1048,14 @@ class gpkg: |
29 |
self._add_signature(checksum_info, image_tarinfo, container) |
30 |
|
31 |
self._add_manifest(container) |
32 |
+ |
33 |
+ # Check if all directories are the same in the container |
34 |
+ prefix = os.path.commonpath(container.getnames()) |
35 |
+ if not prefix: |
36 |
+ raise InvalidBinaryPackageFormat( |
37 |
+ f"gpkg file structure mismatch in {self.gpkg_file}" |
38 |
+ ) |
39 |
+ |
40 |
container.close() |
41 |
|
42 |
def decompress(self, decompress_dir): |
43 |
@@ -1132,9 +1140,9 @@ class gpkg: |
44 |
os.path.join(self.prefix, file_name_old) |
45 |
) |
46 |
new_data_tarinfo = copy(old_data_tarinfo) |
47 |
- new_data_tarinfo.name = new_data_tarinfo.name.replace( |
48 |
- old_basename, new_basename, 1 |
49 |
- ) |
50 |
+ new_file_path = list(os.path.split(new_data_tarinfo.name)) |
51 |
+ new_file_path[0] = new_basename |
52 |
+ new_data_tarinfo.name = os.path.join(*new_file_path) |
53 |
container.addfile( |
54 |
new_data_tarinfo, container_old.extractfile(old_data_tarinfo) |
55 |
) |
56 |
@@ -1142,6 +1150,13 @@ class gpkg: |
57 |
|
58 |
self._add_manifest(container) |
59 |
|
60 |
+ # Check if all directories are the same in the container |
61 |
+ prefix = os.path.commonpath(container.getnames()) |
62 |
+ if not prefix: |
63 |
+ raise InvalidBinaryPackageFormat( |
64 |
+ f"gpkg file structure mismatch in {self.gpkg_file}" |
65 |
+ ) |
66 |
+ |
67 |
shutil.move(tmp_gpkg_file_name, self.gpkg_file) |
68 |
|
69 |
def update_signature(self, keep_current_signature=False): |
70 |
@@ -1222,6 +1237,13 @@ class gpkg: |
71 |
|
72 |
self._add_manifest(container) |
73 |
|
74 |
+ # Check if all directories are the same in the container |
75 |
+ prefix = os.path.commonpath(container.getnames()) |
76 |
+ if not prefix: |
77 |
+ raise InvalidBinaryPackageFormat( |
78 |
+ f"gpkg file structure mismatch in {self.gpkg_file}" |
79 |
+ ) |
80 |
+ |
81 |
shutil.move(tmp_gpkg_file_name, self.gpkg_file) |
82 |
|
83 |
def _add_metadata(self, container, metadata, compression_cmd): |
84 |
@@ -1438,6 +1460,14 @@ class gpkg: |
85 |
self._add_signature(checksum_info, image_tarinfo, container) |
86 |
|
87 |
self._add_manifest(container) |
88 |
+ |
89 |
+ # Check if all directories are the same in the container |
90 |
+ prefix = os.path.commonpath(container.getnames()) |
91 |
+ if not prefix: |
92 |
+ raise InvalidBinaryPackageFormat( |
93 |
+ f"gpkg file structure mismatch in {self.gpkg_file}" |
94 |
+ ) |
95 |
+ |
96 |
container.close() |
97 |
|
98 |
def _record_checksum(self, checksum_info, tarinfo): |