]> arthur.barton.de Git - bup.git/commitdiff
Fix fsyncing on OSX on SMB file-systems
authorJonathan Wright <quaggy@gmail.com>
Tue, 28 Jun 2016 23:22:41 +0000 (16:22 -0700)
committerRob Browning <rlb@defaultvalue.org>
Fri, 1 Jul 2016 05:18:20 +0000 (00:18 -0500)
Fixes the error:

    Traceback (most recent call last):
      File "/usr/local/Cellar/bup/0.28.1/lib/bup/cmd/bup-server", line 209, in <module>
cmd(conn, rest)
      File "/usr/local/Cellar/bup/0.28.1/lib/bup/cmd/bup-server", line 91, in receive_objects_v2
fullpath = w.close(run_midx=not dumb_server_mode)
      File "/usr/local/Cellar/bup/0.28.1/lib/bup/bup/git.py", line 790, in close
return self._end(run_midx=run_midx)
      File "/usr/local/Cellar/bup/0.28.1/lib/bup/bup/git.py", line 764, in _end
fdatasync(f.fileno())
      File "/usr/local/Cellar/bup/0.28.1/lib/bup/bup/helpers.py", line 47, in <lambda>
fdatasync = lambda fd : fcntl.fcntl(fd, fcntl.F_FULLFSYNC)
    IOError: [Errno 45] Operation not supported
    Traceback (most recent call last):
      File "/usr/local/Cellar/bup/0.28.1/lib/bup/cmd/bup-save", line 460, in <module>
w.close()  # must close before we can update the ref
      File "/usr/local/Cellar/bup/0.28.1/lib/bup/bup/client.py", line 317, in close
id = self._end()
      File "/usr/local/Cellar/bup/0.28.1/lib/bup/bup/client.py", line 314, in _end
return self.suggest_packs() # Returns last idx received
      File "/usr/local/Cellar/bup/0.28.1/lib/bup/bup/client.py", line 229, in _suggest_packs
self.check_ok()
      File "/usr/local/Cellar/bup/0.28.1/lib/bup/bup/client.py", line 134, in check_ok
% rv)

Signed-off-by: Jonathan Wright <quaggy@gmail.com>
Reviewed-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
lib/bup/helpers.py

index 581a4bb3827465ab983f7afe4ba1602b44357870..5da2b1a2844aff372fb136332b221416e6a3c27f 100644 (file)
@@ -41,15 +41,25 @@ def atof(s):
 buglvl = atoi(os.environ.get('BUP_DEBUG', 0))
 
 
+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
+    # Apparently os.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
+    def fdatasync(fd):
+        try:
+            return fcntl.fcntl(fd, fcntl.F_FULLFSYNC)
+        except IOError as e:
+            # Fallback for file systems (SMB) that do not support F_FULLFSYNC
+            if e.errno == errno.ENOTSUP:
+                return _fdatasync(fd)
+            else:
+                raise
+else:
+    fdatasync = _fdatasync
 
 
 # Write (blockingly) to sockets that may or may not be in blocking mode.