mirror of
https://github.com/borgbackup/borg.git
synced 2024-12-26 01:37:20 +00:00
sync the containing directory also
This commit is contained in:
parent
fde5a60549
commit
99566a31c0
2 changed files with 14 additions and 0 deletions
|
@ -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
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
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 @@ def get_write_fd(self, no_new=False, raise_full=False):
|
||||||
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 @@ def close_segment(self):
|
||||||
# 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
|
||||||
|
|
Loading…
Reference in a new issue