From 3b0bafc82f8fa5bba4f33905dbb7c331d185cf1f Mon Sep 17 00:00:00 2001 From: Bruno Behnken Date: Sat, 10 Jul 2021 12:18:12 -0300 Subject: [PATCH] Adding try/finally block to make sure cleanup happens --- src/borg/archiver.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/borg/archiver.py b/src/borg/archiver.py index 08bce2e4e..ec181e3c8 100644 --- a/src/borg/archiver.py +++ b/src/borg/archiver.py @@ -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 = [