From: Rob Browning Date: Tue, 3 Dec 2013 18:39:37 +0000 (-0600) Subject: Add helpers.fdatasync(); fix interleaved mmap/read-write in midx. X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=360205500c02eefc98432677cfebcb1e4a832a0c;p=packages%2Fb%2Fbup.git Add helpers.fdatasync(); fix interleaved mmap/read-write in midx. Have helpers.fdatasync() fall back to os.fsync() whenever os.fdatasync() isn't available. Thanks to Yann Autissier for reporting the problem that prompted this work. Signed-off-by: Rob Browning --- diff --git a/cmd/midx-cmd.py b/cmd/midx-cmd.py index 62011e4..392fa8c 100755 --- a/cmd/midx-cmd.py +++ b/cmd/midx-cmd.py @@ -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)) diff --git a/lib/bup/helpers.py b/lib/bup/helpers.py index 6e85fda..19035d1 100644 --- a/lib/bup/helpers.py +++ b/lib/bup/helpers.py @@ -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,