]> arthur.barton.de Git - bup.git/commitdiff
Add helpers.fdatasync(); fix interleaved mmap/read-write in midx.
authorRob Browning <rlb@defaultvalue.org>
Tue, 3 Dec 2013 18:39:37 +0000 (12:39 -0600)
committerRob Browning <rlb@defaultvalue.org>
Thu, 5 Dec 2013 20:35:40 +0000 (14:35 -0600)
Have helpers.fdatasync() fall back to os.fsync() whenever
os.fdatasync() isn't available.

Thanks to Yann Autissier <yann.autissier@gmail.com> for reporting the
problem that prompted this work.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
cmd/midx-cmd.py
lib/bup/helpers.py

index 62011e4a33cf4eb70ed383ca3a57f35d74c5814b..392fa8c3a9ab34423ec1a08e5f9150d4c2331acc 100755 (executable)
@@ -117,11 +117,13 @@ def _do_midx(outdir, outfilename, infilenames, prefixstr):
     assert(f.tell() == 12)
 
     f.truncate(12 + 4*entries + 20*total + 4*total)
+    f.flush()
+    fdatasync(f.fileno())
 
     fmap = mmap_readwrite(f, close=False)
 
     count = merge_into(fmap, bits, total, inp)
-    del fmap
+    del fmap # Assume this calls msync() now.
 
     f.seek(0, os.SEEK_END)
     f.write('\0'.join(allfilenames))
index 6e85fda82dedee928805a075f890a545424043e6..19035d1d1c3ed74f5b6b78fb0a404e17ca8ed158 100644 (file)
@@ -31,6 +31,13 @@ def atof(s):
 buglvl = atoi(os.environ.get('BUP_DEBUG', 0))
 
 
+# If the platform doesn't have fdatasync (OS X), fall back to fsync.
+try:
+    fdatasync = os.fdatasync
+except AttributeError:
+    fdatasync = os.fsync
+
+
 # Write (blockingly) to sockets that may or may not be in blocking mode.
 # We need this because our stderr is sometimes eaten by subprocesses
 # (probably ssh) that sometimes make it nonblocking, if only temporarily,