mirror of
https://github.com/borgbackup/borg.git
synced 2024-12-28 02:38:43 +00:00
Merge pull request #5901 from brunobehnken/master
Adding try/finally block to make sure cleanup happens
This commit is contained in:
commit
40eaaf2cfb
1 changed files with 12 additions and 10 deletions
|
@ -456,16 +456,18 @@ def measurement_run(repo, path):
|
|||
|
||||
@contextmanager
|
||||
def test_files(path, count, size, random):
|
||||
path = os.path.join(path, 'borg-test-data')
|
||||
os.makedirs(path)
|
||||
z_buff = None if random else memoryview(zeros)[:size] if size <= len(zeros) else b'\0' * size
|
||||
for i in range(count):
|
||||
fname = os.path.join(path, 'file_%d' % i)
|
||||
data = z_buff if not random else os.urandom(size)
|
||||
with SyncFile(fname, binary=True) as fd: # used for posix_fadvise's sake
|
||||
fd.write(data)
|
||||
yield path
|
||||
shutil.rmtree(path)
|
||||
try:
|
||||
path = os.path.join(path, 'borg-test-data')
|
||||
os.makedirs(path)
|
||||
z_buff = None if random else memoryview(zeros)[:size] if size <= len(zeros) else b'\0' * size
|
||||
for i in range(count):
|
||||
fname = os.path.join(path, 'file_%d' % i)
|
||||
data = z_buff if not random else os.urandom(size)
|
||||
with SyncFile(fname, binary=True) as fd: # used for posix_fadvise's sake
|
||||
fd.write(data)
|
||||
yield path
|
||||
finally:
|
||||
shutil.rmtree(path)
|
||||
|
||||
if '_BORG_BENCHMARK_CRUD_TEST' in os.environ:
|
||||
tests = [
|
||||
|
|
Loading…
Reference in a new issue