← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:pool-file-not-unique into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:pool-file-not-unique into launchpad:master.

Commit message:
Tolerate multiple pool files with the same name

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/430906

This happens in practice with shared `.orig.tar.*` source files before librarian garbage-collection has merged duplicates.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:pool-file-not-unique into launchpad:master.
diff --git a/lib/lp/soyuz/model/archive.py b/lib/lp/soyuz/model/archive.py
index 9494fa4..a0dbbbc 100644
--- a/lib/lp/soyuz/model/archive.py
+++ b/lib/lp/soyuz/model/archive.py
@@ -2078,7 +2078,10 @@ class Archive(SQLBase):
             ]
         )
         return (
-            store.find(LibraryFileAlias, *clauses).config(distinct=True).one()
+            store.find(LibraryFileAlias, *clauses)
+            .config(distinct=True)
+            .order_by("id")
+            .last()
         )
 
     def getBinaryPackageRelease(self, name, version, archtag):
diff --git a/lib/lp/soyuz/tests/test_archive.py b/lib/lp/soyuz/tests/test_archive.py
index 6ab3352..dbef25a 100644
--- a/lib/lp/soyuz/tests/test_archive.py
+++ b/lib/lp/soyuz/tests/test_archive.py
@@ -3325,6 +3325,52 @@ class TestGetPoolFileByPath(TestCaseWithFactory):
             ),
         )
 
+    def test_source_found_multiple(self):
+        # Source uploads that share files are initially uploaded as separate
+        # LFAs, relying on the librarian's garbage-collection job to
+        # deduplicate them later.
+        archive = self.factory.makeArchive()
+        orig_content = b"An original source tarball"
+        orig_lfas = []
+        for i in range(2):
+            spph = self.factory.makeSourcePackagePublishingHistory(
+                archive=archive,
+                status=PackagePublishingStatus.PUBLISHED,
+                sourcepackagename="test-package",
+                component="main",
+            )
+            version = "1-%d" % (i + 1)
+            self.factory.makeSourcePackageReleaseFile(
+                sourcepackagerelease=spph.sourcepackagerelease,
+                library_file=self.factory.makeLibraryFileAlias(
+                    filename="test-package_%s.dsc" % version, db_only=True
+                ),
+            )
+            self.factory.makeSourcePackageReleaseFile(
+                sourcepackagerelease=spph.sourcepackagerelease,
+                library_file=self.factory.makeLibraryFileAlias(
+                    filename="test-package_%s.debian.tar.xz" % version,
+                    db_only=True,
+                ),
+            )
+            orig_lfas.append(
+                self.factory.makeLibraryFileAlias(
+                    filename="test-package_1.orig.tar.xz",
+                    content=orig_content,
+                    db_only=True,
+                )
+            )
+            self.factory.makeSourcePackageReleaseFile(
+                sourcepackagerelease=spph.sourcepackagerelease,
+                library_file=orig_lfas[-1],
+            )
+        self.assertEqual(
+            orig_lfas[-1],
+            archive.getPoolFileByPath(
+                PurePath("pool/main/t/test-package/test-package_1.orig.tar.xz")
+            ),
+        )
+
     def test_binary_not_found(self):
         archive = self.factory.makeArchive()
         self.factory.makeBinaryPackagePublishingHistory(