mirror of
https://github.com/borgbackup/borg.git
synced 2024-12-26 01:37:20 +00:00
fixup: do not access os.POSIX_FADV_* early
before we know posix_fadvise support exists on the platform.
This commit is contained in:
parent
e19537ff6f
commit
7f2a108c94
3 changed files with 5 additions and 4 deletions
|
@ -65,6 +65,7 @@ def sync_dir(path):
|
|||
|
||||
def safe_fadvise(fd, offset, len, advice):
|
||||
if hasattr(os, 'posix_fadvise'):
|
||||
advice = getattr(os, 'POSIX_FADV_' + advice)
|
||||
try:
|
||||
os.posix_fadvise(fd, offset, len, advice)
|
||||
except OSError:
|
||||
|
@ -120,7 +121,7 @@ def sync(self):
|
|||
platform.fdatasync(self.fileno)
|
||||
# tell the OS that it does not need to cache what we just wrote,
|
||||
# avoids spoiling the cache for the OS and other processes.
|
||||
safe_fadvise(self.fileno, 0, 0, os.POSIX_FADV_DONTNEED)
|
||||
safe_fadvise(self.fileno, 0, 0, 'DONTNEED')
|
||||
|
||||
def close(self):
|
||||
"""sync() and close."""
|
||||
|
|
|
@ -217,7 +217,7 @@ cdef _sync_file_range(fd, offset, length, flags):
|
|||
assert length & PAGE_MASK == 0, "length %d not page-aligned" % length
|
||||
if sync_file_range(fd, offset, length, flags) != 0:
|
||||
raise OSError(errno.errno, os.strerror(errno.errno))
|
||||
safe_fadvise(fd, offset, length, os.POSIX_FADV_DONTNEED)
|
||||
safe_fadvise(fd, offset, length, 'DONTNEED')
|
||||
|
||||
cdef unsigned PAGE_MASK = resource.getpagesize() - 1
|
||||
|
||||
|
@ -254,7 +254,7 @@ class SyncFile(BaseSyncFile):
|
|||
os.fdatasync(self.fileno)
|
||||
# tell the OS that it does not need to cache what we just wrote,
|
||||
# avoids spoiling the cache for the OS and other processes.
|
||||
safe_fadvise(self.fileno, 0, 0, os.POSIX_FADV_DONTNEED)
|
||||
safe_fadvise(self.fileno, 0, 0, 'DONTNEED')
|
||||
|
||||
|
||||
def umount(mountpoint):
|
||||
|
|
|
@ -909,7 +909,7 @@ def close(self):
|
|||
self.fds = None # Just to make sure we're disabled
|
||||
|
||||
def close_fd(self, fd):
|
||||
safe_fadvise(fd.fileno(), 0, 0, os.POSIX_FADV_DONTNEED)
|
||||
safe_fadvise(fd.fileno(), 0, 0, 'DONTNEED')
|
||||
fd.close()
|
||||
|
||||
def segment_iterator(self, segment=None, reverse=False):
|
||||
|
|
Loading…
Reference in a new issue