1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2025-02-22 14:11:27 +00:00

Merge branch 'sparse_files' into merge

This commit is contained in:
Thomas Waldmann 2015-04-27 00:48:28 +02:00
commit ca385e5e7a

View file

@ -207,11 +207,14 @@ def _set_repository_id(self, path, id):
return Repository(self.repository_path).id
def test_sparse_file(self):
# no sparse file support on Mac OS X
sparse_support = sys.platform != 'darwin'
filename = os.path.join(self.input_path, 'sparse')
content = b'foobar'
hole_size = 5 * CHUNK_MAX # 5 full chunker buffers
with open(filename, 'wb') as fd:
# create a file that has a hole at the beginning and end
# create a file that has a hole at the beginning and end (if the
# OS and filesystem supports sparse files)
fd.seek(hole_size, 1)
fd.write(content)
fd.seek(hole_size, 1)
@ -220,7 +223,7 @@ def test_sparse_file(self):
total_len = hole_size + len(content) + hole_size
st = os.stat(filename)
self.assert_equal(st.st_size, total_len)
if hasattr(st, 'st_blocks'):
if sparse_support and hasattr(st, 'st_blocks'):
self.assert_true(st.st_blocks * 512 < total_len / 10) # is input sparse?
self.attic('init', self.repository_location)
self.attic('create', self.repository_location + '::test', 'input')
@ -235,7 +238,7 @@ def test_sparse_file(self):
self.assert_equal(fd.read(hole_size), b'\0' * hole_size)
st = os.stat(filename)
self.assert_equal(st.st_size, total_len)
if hasattr(st, 'st_blocks'):
if sparse_support and hasattr(st, 'st_blocks'):
self.assert_true(st.st_blocks * 512 < total_len / 10) # is output sparse?
def test_repository_swap_detection(self):