← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~cjwatson/launchpad/librarian-find-by-sha256 into lp:launchpad

 

Colin Watson has proposed merging lp:~cjwatson/launchpad/librarian-find-by-sha256 into lp:launchpad.

Commit message:
Replace ILibraryFileAliasSet.findBySHA1 with ILibraryFileAliasSet.findBySHA256.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/librarian-find-by-sha256/+merge/288956

LibraryFileContent.sha256 was backfilled ages ago, so there's no reason to be looking LFAs up by SHA-1 any more.  Move all this to SHA-256.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/librarian-find-by-sha256 into lp:launchpad.
=== modified file 'lib/lp/services/librarian/doc/librarian.txt'
--- lib/lp/services/librarian/doc/librarian.txt	2014-09-01 11:44:56 +0000
+++ lib/lp/services/librarian/doc/librarian.txt	2016-03-14 16:45:42 +0000
@@ -80,14 +80,15 @@
     datetime.datetime(...)
 
 We can retrieve the LibraryFileAlias we just created using its ID or
-sha1.
+sha256.
 
     >>> org_alias_id = alias.id
     >>> alias = lfas[org_alias_id]
     >>> alias.id == org_alias_id
     True
 
-    >>> org_alias_id in [a.id for a in lfas.findBySHA1(alias.content.sha1)]
+    >>> org_alias_id in [
+    ...     a.id for a in lfas.findBySHA256(alias.content.sha256)]
     True
 
 We can get its URL too

=== modified file 'lib/lp/services/librarian/interfaces/__init__.py'
--- lib/lp/services/librarian/interfaces/__init__.py	2013-06-13 07:31:30 +0000
+++ lib/lp/services/librarian/interfaces/__init__.py	2016-03-14 16:45:42 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2016 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Librarian interfaces."""
@@ -171,9 +171,9 @@
     def __getitem__(key):
         """Lookup an ILibraryFileAlias by id."""
 
-    def findBySHA1(sha1):
-        """Return all LibraryFileAlias whose content's sha1 match the given
-        sha1.
+    def findBySHA256(sha256):
+        """Return all LibraryFileAlias whose content's sha256 match the
+        given sha256.
         """
 
 

=== modified file 'lib/lp/services/librarian/model.py'
--- lib/lp/services/librarian/model.py	2015-10-14 15:22:01 +0000
+++ lib/lp/services/librarian/model.py	2016-03-14 16:45:42 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009-2011 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2016 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 __metaclass__ = type
@@ -262,12 +262,12 @@
         """See ILibraryFileAliasSet.__getitem__"""
         return LibraryFileAlias.get(key)
 
-    def findBySHA1(self, sha1):
+    def findBySHA256(self, sha256):
         """See ILibraryFileAliasSet."""
         return LibraryFileAlias.select("""
             content = LibraryFileContent.id
-            AND LibraryFileContent.sha1 = '%s'
-            """ % sha1, clauseTables=['LibraryFileContent'])
+            AND LibraryFileContent.sha256 = '%s'
+            """ % sha256, clauseTables=['LibraryFileContent'])
 
 
 @implementer(ILibraryFileDownloadCount)

=== modified file 'lib/lp/services/librarianserver/testing/fake.py'
--- lib/lp/services/librarianserver/testing/fake.py	2015-07-08 16:05:11 +0000
+++ lib/lp/services/librarianserver/testing/fake.py	2016-03-14 16:45:42 +0000
@@ -1,4 +1,4 @@
-# Copyright 2010 Canonical Ltd.  This software is licensed under the
+# Copyright 2010-2016 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Fake, in-process implementation of the Librarian API.
@@ -174,10 +174,10 @@
                 "librarian, who has never heard of it." % key)
         return alias
 
-    def findBySHA1(self, sha1):
+    def findBySHA256(self, sha256):
         "See `ILibraryFileAliasSet`."""
         for alias in self.aliases.itervalues():
-            if alias.content.sha1 == sha1:
+            if alias.content.sha256 == sha256:
                 return alias
 
         return None

=== modified file 'lib/lp/soyuz/scripts/gina/library.py'
--- lib/lp/soyuz/scripts/gina/library.py	2015-10-21 09:37:08 +0000
+++ lib/lp/soyuz/scripts/gina/library.py	2016-03-14 16:45:42 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2016 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Library access methods to gina."""
@@ -44,11 +44,11 @@
 def checkLibraryForFile(path, filename):
     fullpath = os.path.join(path, filename)
     assert os.path.exists(fullpath)
-    digester = hashlib.sha1()
+    digester = hashlib.sha256()
     openfile = open(fullpath, "r")
     for chunk in iter(lambda: openfile.read(1024 * 4), ''):
         digester.update(chunk)
     digest = digester.hexdigest()
     openfile.close()
     librarian = getUtility(ILibraryFileAliasSet)
-    return not librarian.findBySHA1(digest).is_empty()
+    return not librarian.findBySHA256(digest).is_empty()

=== modified file 'lib/lp/translations/tests/test_exportresult.py'
--- lib/lp/translations/tests/test_exportresult.py	2011-12-30 01:48:17 +0000
+++ lib/lp/translations/tests/test_exportresult.py	2016-03-14 16:45:42 +0000
@@ -1,4 +1,4 @@
-# Copyright 2010 Canonical Ltd.  This software is licensed under the
+# Copyright 2010-2016 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Tests for `ExportResult`."""
@@ -56,9 +56,9 @@
         export_result.upload()
 
         self.assertIsNot(None, export_result.url)
-        sha1 = hashlib.sha1(export.content).hexdigest()
-        self.assertEqual(sha1, librarian.aliases.values()[0].content.sha1)
-        alias = librarian.findBySHA1(sha1)
+        sha256 = hashlib.sha256(export.content).hexdigest()
+        self.assertEqual(sha256, librarian.aliases.values()[0].content.sha256)
+        alias = librarian.findBySHA256(sha256)
         self.assertEqual(export.path, alias.filename)
 
     def test_upload_without_exported_file_does_nothing(self):


Follow ups