From adc89c488c67f07edd10f33e8e342f2d9b2683ca Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Mon, 19 Apr 2021 21:07:29 +0200 Subject: [PATCH] fix repeated cache tag file writing bug this bug was introduced by PR #5485 and also affects backport PR #5774. --- src/borg/helpers/fs.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/borg/helpers/fs.py b/src/borg/helpers/fs.py index 65eeb4d51..25c2e5755 100644 --- a/src/borg/helpers/fs.py +++ b/src/borg/helpers/fs.py @@ -87,13 +87,15 @@ def get_cache_dir(): cache_dir = os.environ.get('BORG_CACHE_DIR', os.path.join(cache_home, 'borg')) # Create path if it doesn't exist yet ensure_dir(cache_dir) - with open(os.path.join(cache_dir, CACHE_TAG_NAME), 'wb') as fd: - fd.write(CACHE_TAG_CONTENTS) - fd.write(textwrap.dedent(""" - # This file is a cache directory tag created by Borg. - # For information about cache directory tags, see: - # http://www.bford.info/cachedir/spec.html - """).encode('ascii')) + cache_fn = os.path.join(cache_dir, CACHE_TAG_NAME) + if not os.path.exists(cache_fn): + with open(cache_fn, 'wb') as fd: + fd.write(CACHE_TAG_CONTENTS) + fd.write(textwrap.dedent(""" + # This file is a cache directory tag created by Borg. + # For information about cache directory tags, see: + # http://www.bford.info/cachedir/spec.html + """).encode('ascii')) return cache_dir