]> arthur.barton.de Git - bup.git/blobdiff - lib/bup/helpers.py
fdatasync: call F_FULLFSYNC fcntl on OS X
[bup.git] / lib / bup / helpers.py
index 5bae5dee943d477a97f6dd65c73cc154eec089f8..377678bf39332db1fa245d63cb979eee2591e615 100644 (file)
@@ -41,11 +41,15 @@ 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
+if sys.platform.startswith('darwin'):
+    # Apparently fsync on OS X doesn't guarantee to sync all the way down
+    import fcntl
+    fdatasync = lambda fd : fcntl.fcntl(fd, fcntl.F_FULLFSYNC)
+else: # If the platform doesn't have fdatasync, 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.