]> arthur.barton.de Git - bup.git/commitdiff
Skip over invalid .idx files if we find any.
authorAvery Pennarun <apenwarr@gmail.com>
Thu, 23 Dec 2010 02:08:58 +0000 (18:08 -0800)
committerAvery Pennarun <apenwarr@gmail.com>
Thu, 23 Dec 2010 02:08:58 +0000 (18:08 -0800)
There's no particular reason to make it fatal; just pretend they're not
there.

Zoran reported a bug where he had (it seems) some zero-length .idx files,
which is weird, but nothing worth aborting a backup over.

Also, fix _mmap_do() to be able to handle mmap'ing a zero-length file
without an error.  It's a trivial and somewhat pointless operation, but it
shouldn't throw an exception.

Signed-off-by: Avery Pennarun <apenwarr@gmail.com>
lib/bup/git.py
lib/bup/helpers.py

index 1dbf61f69e0211435d97cfd928a2249e5b72e0bb..6a65c435450233702dea291113c417e423c0419f 100644 (file)
@@ -423,7 +423,11 @@ class PackIdxList:
             for f in os.listdir(self.dir):
                 full = os.path.join(self.dir, f)
                 if f.endswith('.idx') and not d.get(full):
-                    ix = open_idx(full)
+                    try:
+                        ix = open_idx(full)
+                    except GitError, e:
+                        add_error(e)
+                        continue
                     d[full] = ix
             self.packs = list(set(d.values()))
         debug1('PackIdxList: using %d index%s.\n'
@@ -437,7 +441,11 @@ class PackIdxList:
         for f in os.listdir(self.dir):
             if f.endswith('.idx'):
                 full = os.path.join(self.dir, f)
-                ix = open_idx(full)
+                try:
+                    ix = open_idx(full)
+                except GitError, e:
+                    add_error(e)
+                    continue
                 if ix.exists(hash):
                     return full
 
@@ -477,8 +485,10 @@ def open_idx(filename):
             else:
                 raise GitError('%s: expected idx file version 2, got %d'
                                % (filename, version))
-        else:
+        elif len(header) == 8 and header[0:4] < '\377tOc':
             return PackIdxV1(filename, f)
+        else:
+            raise GitError('%s: unrecognized idx file header' % filename)
     elif filename.endswith('.midx'):
         return PackMidx(filename)
     else:
index bf431455921de2b0d558de67516e2f2201b77198..cb7854338ead99ad13358ad5ec41617dfb31e121 100644 (file)
@@ -284,6 +284,11 @@ def _mmap_do(f, sz, flags, prot):
     if not sz:
         st = os.fstat(f.fileno())
         sz = st.st_size
+    if not sz:
+        # trying to open a zero-length map gives an error, but an empty
+        # string has all the same behaviour of a zero-length map, ie. it has
+        # no elements :)
+        return ''
     map = mmap.mmap(f.fileno(), sz, flags, prot)
     f.close()  # map will persist beyond file close
     return map