← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~cjwatson/launchpad/publisher-xz-checksums into lp:launchpad

 

Colin Watson has proposed merging lp:~cjwatson/launchpad/publisher-xz-checksums into lp:launchpad.

Commit message:
Teach Publisher._readIndexFileHashes to compute uncompressed checksums of .xz files.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/publisher-xz-checksums/+merge/363438
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/publisher-xz-checksums into lp:launchpad.
=== modified file 'lib/lp/archivepublisher/publishing.py'
--- lib/lp/archivepublisher/publishing.py	2018-05-08 15:18:43 +0000
+++ lib/lp/archivepublisher/publishing.py	2019-02-20 16:32:05 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009-2018 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2019 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 __all__ = [
@@ -19,6 +19,7 @@
     timedelta,
     )
 import errno
+from functools import partial
 import gzip
 import hashlib
 from itertools import (
@@ -34,6 +35,10 @@
     _multivalued,
     Release,
     )
+try:
+    import lzma
+except ImportError:
+    from backports import lzma
 import scandir
 from storm.expr import Desc
 from zope.component import getUtility
@@ -1417,6 +1422,9 @@
             elif os.path.exists(full_name + '.bz2'):
                 open_func = bz2.BZ2File
                 full_name = full_name + '.bz2'
+            elif os.path.exists(full_name + '.xz'):
+                open_func = partial(lzma.LZMAFile, format=lzma.FORMAT_XZ)
+                full_name = full_name + '.xz'
             else:
                 # The file we were asked to write out doesn't exist.
                 # Most likely we have an incomplete archive (e.g. no sources

=== modified file 'lib/lp/archivepublisher/tests/test_publisher.py'
--- lib/lp/archivepublisher/tests/test_publisher.py	2018-05-08 15:18:43 +0000
+++ lib/lp/archivepublisher/tests/test_publisher.py	2019-02-20 16:32:05 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009-2018 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2019 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Tests for publisher class."""
@@ -2408,6 +2408,44 @@
 
         self.assertFalse(os.path.exists(os.path.join(i18n_root, 'Index')))
 
+    def testReadIndexFileHashesCompression(self):
+        """Test compressed file handling in _readIndexFileHashes."""
+        publisher = Publisher(
+            self.logger, self.config, self.disk_pool,
+            self.ubuntutest.main_archive)
+        contents = b'test'
+        path = os.path.join(
+            publisher._config.distsroot, 'breezy-autotest', 'Test')
+        os.makedirs(os.path.dirname(path))
+        for suffix, open_func in (
+                ('', open),
+                ('.gz', gzip.open),
+                ('.bz2', bz2.BZ2File),
+                ('.xz', partial(lzma.LZMAFile, format=lzma.FORMAT_XZ)),
+                ):
+            with open_func(path + suffix, mode='wb') as f:
+                f.write(contents)
+            self.assertEqual(
+                {
+                    'md5sum': {
+                        'md5sum': hashlib.md5(contents).hexdigest(),
+                        'name': 'Test',
+                        'size': len(contents),
+                        },
+                    'sha1': {
+                        'sha1': hashlib.sha1(contents).hexdigest(),
+                        'name': 'Test',
+                        'size': len(contents),
+                        },
+                    'sha256': {
+                        'sha256': hashlib.sha256(contents).hexdigest(),
+                        'name': 'Test',
+                        'size': len(contents),
+                        },
+                    },
+                publisher._readIndexFileHashes('breezy-autotest', 'Test'))
+            os.remove(path + suffix)
+
 
 class TestArchiveIndices(TestPublisherBase):
     """Tests for the native publisher's index generation.


Follow ups