commit:     ef3ad9396d9fe2ae7d34b640f8318d218be8bae6
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Fri Dec  2 03:41:26 2022 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri Dec  2 21:07:19 2022 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=ef3ad939

bintree: Fix breaking GPKG structure on updates

Fix passing the wrong basename to the gpkg initializer when performing
package updates.  This caused newly written files to be missing
build_id and therefore causing a structure mismatch.

Bug: https://bugs.gentoo.org/877271
Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>
Closes: https://github.com/gentoo/portage/pull/955
Signed-off-by: Sam James <sam <AT> gentoo.org>

 NEWS                         | 4 +++-
 lib/portage/dbapi/bintree.py | 7 +++++--
 lib/portage/gpkg.py          | 3 ++-
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/NEWS b/NEWS
index a907526aa..ad762993b 100644
--- a/NEWS
+++ b/NEWS
@@ -7,7 +7,9 @@ Features:
   by using ewarn rather than eerror.
 
 Bug fixes:
-* TODO
+* Fixed possible corruption of GPKG multi-instance binary packages on upgrade.
+  Bug #877271.
+
 
 portage-3.0.40 (2022-12-01)
 --------------

diff --git a/lib/portage/dbapi/bintree.py b/lib/portage/dbapi/bintree.py
index baf001c8f..12f82bdfd 100644
--- a/lib/portage/dbapi/bintree.py
+++ b/lib/portage/dbapi/bintree.py
@@ -244,7 +244,6 @@ class bindbapi(fakedbapi):
     def aux_update(self, cpv, values):
         if not self.bintree.populated:
             self.bintree.populate()
-        build_id = None
         try:
             build_id = cpv.build_id
         except AttributeError:
@@ -257,6 +256,10 @@ class bindbapi(fakedbapi):
                 cpv = self._instance_key(cpv, support_string=True)[0]
                 build_id = cpv.build_id
 
+        cpv_str = str(cpv)
+        if build_id is not None:
+            cpv_str += f"-{build_id}"
+
         binpkg_path = self.bintree.getname(cpv)
         if not os.path.exists(binpkg_path):
             raise KeyError(cpv)
@@ -267,7 +270,7 @@ class bindbapi(fakedbapi):
             mydata = mytbz2.get_data()
             encoding_key = True
         elif binpkg_format == "gpkg":
-            mybinpkg = portage.gpkg.gpkg(self.settings, cpv, binpkg_path)
+            mybinpkg = portage.gpkg.gpkg(self.settings, cpv_str, binpkg_path)
             mydata = mybinpkg.get_metadata()
             encoding_key = False
         else:

diff --git a/lib/portage/gpkg.py b/lib/portage/gpkg.py
index 561fa4450..a82f8bd49 100644
--- a/lib/portage/gpkg.py
+++ b/lib/portage/gpkg.py
@@ -1150,7 +1150,8 @@ class gpkg:
             prefix = os.path.commonpath(container.getnames())
             if not prefix:
                 raise InvalidBinaryPackageFormat(
-                    f"gpkg file structure mismatch in {self.gpkg_file}"
+                    f"gpkg file structure mismatch in {self.gpkg_file}; files: 
"
+                    f"{container.getnames()}"
                 )
 
         shutil.move(tmp_gpkg_file_name, self.gpkg_file)

Reply via email to