fix repeated cache tag file writing bug

this bug was introduced by PR #5485 and also affects backport PR #5774.
This commit is contained in:
Thomas Waldmann 2021-04-19 21:07:29 +02:00
parent 426f5e8335
commit adc89c488c
1 changed files with 9 additions and 7 deletions

View File

@ -87,7 +87,9 @@ 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:
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.