obscache: have the obsstore fix empty file cachekey
authorPierre-Yves David <pierre-yves.david@ens-lyon.org>
Tue, 02 May 2017 16:10:14 +0200
changeset 2306 b33bc2f37e89
parent 2305 a786240c95bd
child 2307 0d2e0e8e76f6
obscache: have the obsstore fix empty file cachekey Before this change, the missing file and empty file returned different value.
hgext3rd/evolve/obscache.py
--- a/hgext3rd/evolve/obscache.py	Tue May 02 17:44:12 2017 +0200
+++ b/hgext3rd/evolve/obscache.py	Tue May 02 16:10:14 2017 +0200
@@ -56,6 +56,10 @@
 
             If the index specified is higher than the current obsstore file
             length, cachekey will be set to None."""
+            # default value
+            obsstoresize = 0
+            keydata = ''
+            # try to get actual data from the obsstore
             try:
                 with self.svfs('obsstore') as obsfile:
                     obsfile.seek(0, 2)
@@ -65,13 +69,14 @@
                     elif obsstoresize < index:
                         return obsstoresize, None
                     actualsize = min(index, self._obskeysize)
-                    obsfile.seek(index - actualsize, 0)
-                    keydata = obsfile.read(actualsize)
-                return obsstoresize, hashlib.sha1(keydata).digest()
+                    if actualsize:
+                        obsfile.seek(index - actualsize, 0)
+                        keydata = obsfile.read(actualsize)
             except (OSError, IOError) as e:
                 if e.errno != errno.ENOENT:
                     raise
-                return 0, node.nullid
+            key = hashlib.sha1(keydata).digest()
+            return obsstoresize, key
 
     obsstore.__class__ = cachekeyobsstore