Parcourir la source

fixup: do not access os.POSIX_FADV_* early

before we know posix_fadvise support exists on the platform.
Thomas Waldmann il y a 8 ans
Parent
commit
7f2a108c94
3 fichiers modifiés avec 5 ajouts et 4 suppressions
  1. 2 1
      src/borg/platform/base.py
  2. 2 2
      src/borg/platform/linux.pyx
  3. 1 1
      src/borg/repository.py

+ 2 - 1
src/borg/platform/base.py

@@ -65,6 +65,7 @@ def sync_dir(path):
 
 
 def safe_fadvise(fd, offset, len, advice):
 def safe_fadvise(fd, offset, len, advice):
     if hasattr(os, 'posix_fadvise'):
     if hasattr(os, 'posix_fadvise'):
+        advice = getattr(os, 'POSIX_FADV_' + advice)
         try:
         try:
             os.posix_fadvise(fd, offset, len, advice)
             os.posix_fadvise(fd, offset, len, advice)
         except OSError:
         except OSError:
@@ -120,7 +121,7 @@ class SyncFile:
         platform.fdatasync(self.fileno)
         platform.fdatasync(self.fileno)
         # tell the OS that it does not need to cache what we just wrote,
         # tell the OS that it does not need to cache what we just wrote,
         # avoids spoiling the cache for the OS and other processes.
         # 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):
     def close(self):
         """sync() and close."""
         """sync() and close."""

+ 2 - 2
src/borg/platform/linux.pyx

@@ -217,7 +217,7 @@ cdef _sync_file_range(fd, offset, length, flags):
     assert length & PAGE_MASK == 0, "length %d not page-aligned" % length
     assert length & PAGE_MASK == 0, "length %d not page-aligned" % length
     if sync_file_range(fd, offset, length, flags) != 0:
     if sync_file_range(fd, offset, length, flags) != 0:
         raise OSError(errno.errno, os.strerror(errno.errno))
         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
 cdef unsigned PAGE_MASK = resource.getpagesize() - 1
 
 
@@ -254,7 +254,7 @@ class SyncFile(BaseSyncFile):
         os.fdatasync(self.fileno)
         os.fdatasync(self.fileno)
         # tell the OS that it does not need to cache what we just wrote,
         # tell the OS that it does not need to cache what we just wrote,
         # avoids spoiling the cache for the OS and other processes.
         # 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):
 def umount(mountpoint):

+ 1 - 1
src/borg/repository.py

@@ -909,7 +909,7 @@ class LoggedIO:
         self.fds = None  # Just to make sure we're disabled
         self.fds = None  # Just to make sure we're disabled
 
 
     def close_fd(self, fd):
     def close_fd(self, fd):
-        safe_fadvise(fd.fileno(), 0, 0, os.POSIX_FADV_DONTNEED)
+        safe_fadvise(fd.fileno(), 0, 0, 'DONTNEED')
         fd.close()
         fd.close()
 
 
     def segment_iterator(self, segment=None, reverse=False):
     def segment_iterator(self, segment=None, reverse=False):