changeset 37145:56c7cd067477

lfs: add a blob verification method to the local store A corrupt blob can be signaled through the Batch API response, without actually transferring the file. A true/false indicator is slightly easier than immediately catching an exception.
author Matt Harbison <matt_harbison@yahoo.com>
date Thu, 22 Feb 2018 23:33:52 -0500
parents 004ecdbe96ec
children c37c47e47a95
files hgext/lfs/blobstore.py
diffstat 1 files changed, 11 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/lfs/blobstore.py	Wed Mar 28 22:38:01 2018 -0400
+++ b/hgext/lfs/blobstore.py	Thu Feb 22 23:33:52 2018 -0500
@@ -175,6 +175,17 @@
             _verify(oid, blob)
         return blob
 
+    def verify(self, oid):
+        """Indicate whether or not the hash of the underlying file matches its
+        name."""
+        sha256 = hashlib.sha256()
+
+        with self.open(oid) as fp:
+            for chunk in util.filechunkiter(fp, size=1048576):
+                sha256.update(chunk)
+
+        return oid == sha256.hexdigest()
+
     def has(self, oid):
         """Returns True if the local blobstore contains the requested blob,
         False otherwise."""