浏览代码

skip sparse tests if has_seek_hole is False

also: do the os.SEEK_(HOLE|DATA) check only once
Thomas Waldmann 4 年之前
父节点
当前提交
c0c0da9c76
共有 3 个文件被更改,包括 12 次插入3 次删除
  1. 7 1
      src/borg/chunker.pyx
  2. 2 1
      src/borg/testsuite/archiver.py
  3. 3 1
      src/borg/testsuite/chunker_pytest.py

+ 7 - 1
src/borg/chunker.pyx

@@ -20,6 +20,12 @@ cdef extern from "_chunker.c":
     uint32_t c_buzhash_update  "buzhash_update"(uint32_t sum, unsigned char remove, unsigned char add, size_t len, uint32_t *h)
 
 
+# this will be True if Python's seek implementation supports data/holes seeking.
+# this does not imply that it will actually work on the filesystem,
+# because the FS also needs to support this.
+has_seek_hole = hasattr(os, 'SEEK_DATA') and hasattr(os, 'SEEK_HOLE')
+
+
 def dread(offset, size, fd=None, fh=-1):
     use_fh = fh >= 0
     if use_fh:
@@ -117,7 +123,7 @@ class ChunkerFixed:
         self.header_size = header_size
         # should borg try to do sparse input processing?
         # whether it actually can be done depends on the input file being seekable.
-        self.try_sparse = sparse and hasattr(os, 'SEEK_DATA') and hasattr(os, 'SEEK_HOLE')
+        self.try_sparse = sparse and has_seek_hole
         self.zeros = memoryview(bytes(block_size))
 
     def chunkify(self, fd=None, fh=-1, fmap=None):

+ 2 - 1
src/borg/testsuite/archiver.py

@@ -32,6 +32,7 @@ from .. import xattr, helpers, platform
 from ..archive import Archive, ChunkBuffer
 from ..archiver import Archiver, parse_storage_quota, PURE_PYTHON_MSGPACK_WARNING
 from ..cache import Cache, LocalCache
+from ..chunker import has_seek_hole
 from ..constants import *  # NOQA
 from ..crypto.low_level import bytes_to_long, num_cipher_blocks
 from ..crypto.key import KeyfileKeyBase, RepoKey, KeyfileKey, Passphrase, TAMRequiredError
@@ -563,7 +564,7 @@ class ArchiverTestCase(ArchiverTestCaseBase):
             sparse = True
             if sparse and hasattr(st, 'st_blocks') and st.st_blocks * 512 >= st.st_size:
                 sparse = False
-            if sparse and hasattr(os, 'SEEK_HOLE') and hasattr(os, 'SEEK_DATA'):
+            if sparse and has_seek_hole:
                 with open(fn, 'rb') as fd:
                     # only check if the first hole is as expected, because the 2nd hole check
                     # is problematic on xfs due to its "dynamic speculative EOF preallocation

+ 3 - 1
src/borg/testsuite/chunker_pytest.py

@@ -3,7 +3,7 @@ import os
 
 import pytest
 
-from ..chunker import ChunkerFixed, sparsemap
+from ..chunker import ChunkerFixed, sparsemap, has_seek_hole
 from ..constants import *  # NOQA
 
 BS = 4096  # fs block size
@@ -65,6 +65,7 @@ def make_content(sparsemap, header_size=0):
     return content
 
 
+@pytest.mark.skipif(not has_seek_hole)
 @pytest.mark.parametrize("fname, sparse_map", [
     ('sparse1', map_sparse1),
     ('sparse2', map_sparse2),
@@ -90,6 +91,7 @@ def test_sparsemap(tmpdir, fname, sparse_map):
     assert get_sparsemap_fd(fn) == sparse_map
 
 
+@pytest.mark.skipif(not has_seek_hole)
 @pytest.mark.parametrize("fname, sparse_map, header_size, sparse", [
     ('sparse1', map_sparse1, 0, False),
     ('sparse1', map_sparse1, 0, True),