2
0
Эх сурвалжийг харах

sync the containing directory also

Thomas Waldmann 9 жил өмнө
parent
commit
99566a31c0

+ 11 - 0
borg/platform.py

@@ -1,5 +1,16 @@
+import os
 import sys
 import sys
 
 
+
+# POSIX-only, from borg 1.1 platform.base
+def sync_dir(path):
+    fd = os.open(path, os.O_RDONLY)
+    try:
+        os.fsync(fd)
+    finally:
+        os.close(fd)
+
+
 if sys.platform.startswith('linux'):  # pragma: linux only
 if sys.platform.startswith('linux'):  # pragma: linux only
     from .platform_linux import acl_get, acl_set, API_VERSION
     from .platform_linux import acl_get, acl_set, API_VERSION
 elif sys.platform.startswith('freebsd'):  # pragma: freebsd only
 elif sys.platform.startswith('freebsd'):  # pragma: freebsd only

+ 3 - 0
borg/repository.py

@@ -16,6 +16,7 @@ from .helpers import Error, ErrorWithTraceback, IntegrityError, Location, Progre
 from .hashindex import NSIndex
 from .hashindex import NSIndex
 from .locking import UpgradableLock, LockError, LockErrorT
 from .locking import UpgradableLock, LockError, LockErrorT
 from .lrucache import LRUCache
 from .lrucache import LRUCache
+from .platform import sync_dir
 
 
 MAX_OBJECT_SIZE = 20 * 1024 * 1024
 MAX_OBJECT_SIZE = 20 * 1024 * 1024
 MAGIC = b'BORG_SEG'
 MAGIC = b'BORG_SEG'
@@ -600,6 +601,7 @@ class LoggedIO:
                 dirname = os.path.join(self.path, 'data', str(self.segment // self.segments_per_dir))
                 dirname = os.path.join(self.path, 'data', str(self.segment // self.segments_per_dir))
                 if not os.path.exists(dirname):
                 if not os.path.exists(dirname):
                     os.mkdir(dirname)
                     os.mkdir(dirname)
+                    sync_dir(os.path.join(self.path, 'data'))
             self._write_fd = open(self.segment_filename(self.segment), 'ab')
             self._write_fd = open(self.segment_filename(self.segment), 'ab')
             self._write_fd.write(MAGIC)
             self._write_fd.write(MAGIC)
             self.offset = MAGIC_LEN
             self.offset = MAGIC_LEN
@@ -744,4 +746,5 @@ class LoggedIO:
                 # avoids spoiling the cache for the OS and other processes.
                 # avoids spoiling the cache for the OS and other processes.
                 os.posix_fadvise(self._write_fd.fileno(), 0, 0, os.POSIX_FADV_DONTNEED)
                 os.posix_fadvise(self._write_fd.fileno(), 0, 0, os.POSIX_FADV_DONTNEED)
             self._write_fd.close()
             self._write_fd.close()
+            sync_dir(os.path.dirname(self._write_fd.name))
             self._write_fd = None
             self._write_fd = None