Skip to content

Commit

Permalink
detect sparse support by fs
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasWaldmann committed Dec 25, 2020
1 parent 18b54f9 commit 7c28c29
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/borg/testsuite/chunker_pytest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from io import BytesIO
import os
import tempfile

import pytest

Expand Down Expand Up @@ -65,7 +66,19 @@ def make_content(sparsemap, header_size=0):
return content


@pytest.mark.skipif(not has_seek_hole)
def fs_supports_sparse():
if not has_seek_hole:
return False
with tempfile.TemporaryDirectory() as tmpdir:
fn = os.path.join(tmpdir, 'test_sparse')
make_sparsefile(fn, [(0, BS, False), (BS, BS, True)])
with open(fn, 'rb') as f:
offset_hole = f.seek(0, os.SEEK_HOLE)
offset_data = f.seek(0, os.SEEK_DATA)
return offset_hole == 0 and offset_data == BS


@pytest.mark.skipif(not fs_supports_sparse())
@pytest.mark.parametrize("fname, sparse_map", [
('sparse1', map_sparse1),
('sparse2', map_sparse2),
Expand All @@ -91,7 +104,7 @@ def get_sparsemap_fd(fname):
assert get_sparsemap_fd(fn) == sparse_map


@pytest.mark.skipif(not has_seek_hole)
@pytest.mark.skipif(not fs_supports_sparse())
@pytest.mark.parametrize("fname, sparse_map, header_size, sparse", [
('sparse1', map_sparse1, 0, False),
('sparse1', map_sparse1, 0, True),
Expand Down

0 comments on commit 7c28c29

Please sign in to comment.