]> arthur.barton.de Git - bup.git/blobdiff - lib/bup/git.py
git.py: flush idx_map before close so FILE* operations will see changes.
[bup.git] / lib / bup / git.py
index 3406edf7863bcd6fe858f607fef9fae62b0afb30..00975a713d8849f9d110d0271b657c535cd3b3d0 100644 (file)
@@ -8,7 +8,6 @@ from bup import _helpers, path, midx, bloom, xstat
 
 max_pack_size = 1000*1000*1000  # larger packs will slow down pruning
 max_pack_objects = 200*1000  # cache memory usage is about 83 bytes per object
-SEEK_END=2  # os.SEEK_END is not defined in python 2.4
 
 verbose = 0
 ignore_midx = 0
@@ -127,7 +126,7 @@ def calc_hash(type, content):
     return sum.digest()
 
 
-def _shalist_sort_key(ent):
+def shalist_item_sort_key(ent):
     (mode, name, id) = ent
     assert(mode+0 == mode)
     if stat.S_ISDIR(mode):
@@ -138,7 +137,7 @@ def _shalist_sort_key(ent):
 
 def tree_encode(shalist):
     """Generate a git tree object from (mode,name,hash) tuples."""
-    shalist = sorted(shalist, key = _shalist_sort_key)
+    shalist = sorted(shalist, key = shalist_item_sort_key)
     l = []
     for (mode,name,bin) in shalist:
         assert(mode)
@@ -662,9 +661,13 @@ class PackWriter:
         idx_f.truncate(ofs64_ofs)
         idx_f.seek(0)
         idx_map = mmap_readwrite(idx_f, close=False)
-        idx_f.seek(0, SEEK_END)
+        idx_f.seek(0, os.SEEK_END)
         count = _helpers.write_idx(idx_f, idx_map, idx, self.count)
         assert(count == self.count)
+        # Sync, since it doesn't look like POSIX guarantees that a
+        # matching FILE* (i.e. idx_f) will see the parallel changes if
+        # we don't.
+        idx_map.flush()
         idx_map.close()
         idx_f.write(packbin)
 
@@ -963,7 +966,8 @@ class CatPipe:
         if not self.p or self.p.poll() != None:
             self._restart()
         assert(self.p)
-        assert(self.p.poll() == None)
+        poll_result = self.p.poll()
+        assert(poll_result == None)
         if self.inprogress:
             log('_fast_get: opening %r while %r is open\n'
                 % (id, self.inprogress))
@@ -989,7 +993,8 @@ class CatPipe:
             yield type
             for blob in it:
                 yield blob
-            assert(self.p.stdout.readline() == '\n')
+            readline_result = self.p.stdout.readline()
+            assert(readline_result == '\n')
             self.inprogress = None
         except Exception, e:
             it.abort()