mirror of
https://github.com/borgbackup/borg.git
synced 2025-02-23 14:41:43 +00:00
Merge branch 'sparse_files' into merge
This commit is contained in:
commit
ca385e5e7a
1 changed files with 6 additions and 3 deletions
|
@ -207,11 +207,14 @@ def _set_repository_id(self, path, id):
|
||||||
return Repository(self.repository_path).id
|
return Repository(self.repository_path).id
|
||||||
|
|
||||||
def test_sparse_file(self):
|
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')
|
filename = os.path.join(self.input_path, 'sparse')
|
||||||
content = b'foobar'
|
content = b'foobar'
|
||||||
hole_size = 5 * CHUNK_MAX # 5 full chunker buffers
|
hole_size = 5 * CHUNK_MAX # 5 full chunker buffers
|
||||||
with open(filename, 'wb') as fd:
|
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.seek(hole_size, 1)
|
||||||
fd.write(content)
|
fd.write(content)
|
||||||
fd.seek(hole_size, 1)
|
fd.seek(hole_size, 1)
|
||||||
|
@ -220,7 +223,7 @@ def test_sparse_file(self):
|
||||||
total_len = hole_size + len(content) + hole_size
|
total_len = hole_size + len(content) + hole_size
|
||||||
st = os.stat(filename)
|
st = os.stat(filename)
|
||||||
self.assert_equal(st.st_size, total_len)
|
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.assert_true(st.st_blocks * 512 < total_len / 10) # is input sparse?
|
||||||
self.attic('init', self.repository_location)
|
self.attic('init', self.repository_location)
|
||||||
self.attic('create', self.repository_location + '::test', 'input')
|
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)
|
self.assert_equal(fd.read(hole_size), b'\0' * hole_size)
|
||||||
st = os.stat(filename)
|
st = os.stat(filename)
|
||||||
self.assert_equal(st.st_size, total_len)
|
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?
|
self.assert_true(st.st_blocks * 512 < total_len / 10) # is output sparse?
|
||||||
|
|
||||||
def test_repository_swap_detection(self):
|
def test_repository_swap_detection(self):
|
||||||
|
|
Loading…
Reference in a new issue