← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:py3-fillLibrarianFile-update-lfc into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:py3-fillLibrarianFile-update-lfc into launchpad:master.

Commit message:
fillLibrarianFile: Update LibraryFileContent metadata

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

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

Python 3's standard HTTP client library is pickier about incomplete reads, so fails if a librarian file is shorter than its file size claims it should be.  Work around this by updating the metadata in LibraryFileContent to match the injected data.  (Strictly we probably only need to update the size, but updating the hashes as well seems likely to avoid confusion at some point.)
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-fillLibrarianFile-update-lfc into launchpad:master.
diff --git a/lib/lp/services/librarianserver/testing/server.py b/lib/lp/services/librarianserver/testing/server.py
index 0ac1a68..12c50d6 100644
--- a/lib/lp/services/librarianserver/testing/server.py
+++ b/lib/lp/services/librarianserver/testing/server.py
@@ -11,6 +11,7 @@ __all__ = [
     'LibrarianServerFixture',
     ]
 
+import hashlib
 import os
 import shutil
 import tempfile
@@ -30,6 +31,7 @@ from lp.services.daemons.tachandler import (
 from lp.services.librarian.model import LibraryFileContent
 from lp.services.librarianserver.storage import _relFileLocation
 from lp.services.osutils import get_pid_from_file
+from lp.testing.dbuser import dbuser
 
 
 class LibrarianServerFixture(TacTestSetup):
@@ -240,8 +242,17 @@ class LibrarianServerFixture(TacTestSetup):
 
 def fillLibrarianFile(fileid, content=None):
     """Write contents in disk for a librarian sampledata."""
-    if content is None:
-        content = b'x' * LibraryFileContent.get(fileid).filesize
+    with dbuser('librariangc'):
+        lfc = LibraryFileContent.get(fileid)
+        if content is None:
+            content = b'x' * lfc.filesize
+        else:
+            lfc.filesize = len(content)
+        lfc.sha256 = hashlib.sha256(content).hexdigest()
+        if lfc.sha1 is not None:
+            lfc.sha1 = hashlib.sha1(content).hexdigest()
+        if lfc.md5 is not None:
+            lfc.md5 = hashlib.md5(content).hexdigest()
 
     filepath = os.path.join(
         config.librarian_server.root, _relFileLocation(fileid))
diff --git a/lib/lp/soyuz/doc/publishing.txt b/lib/lp/soyuz/doc/publishing.txt
index 512b2a6..bacb573 100644
--- a/lib/lp/soyuz/doc/publishing.txt
+++ b/lib/lp/soyuz/doc/publishing.txt
@@ -1252,7 +1252,7 @@ The returned ResultSet element is tuple containing:
     mozilla-firefox_0.9_i386.changes
 
     >>> print(content.md5)
-    e4a7193a8f72fa2755e2162512069093
+    b14d7265706d0f5b19d5812d59a61d2a
 
 Last but not least the publishing set class allows for the bulk deletion
 of publishing history records.

Follow ups