mirror of https://github.com/borgbackup/borg.git
avoid create the cache tag file on every get_cache_dir call
this re-introduces a race between os.path.exists vs. SaveFile creating that file, but due to the way how SaveFile works, it still makes sure that in the end there is a good cache tag file in place.
This commit is contained in:
parent
7f5cd2c4d4
commit
d0a3b30fdf
|
@ -93,14 +93,15 @@ def get_cache_dir():
|
||||||
# Create path if it doesn't exist yet
|
# Create path if it doesn't exist yet
|
||||||
ensure_dir(cache_dir)
|
ensure_dir(cache_dir)
|
||||||
cache_tag_fn = os.path.join(cache_dir, CACHE_TAG_NAME)
|
cache_tag_fn = os.path.join(cache_dir, CACHE_TAG_NAME)
|
||||||
cache_tag_contents = CACHE_TAG_CONTENTS + textwrap.dedent("""
|
if not os.path.exists(cache_tag_fn):
|
||||||
# This file is a cache directory tag created by Borg.
|
cache_tag_contents = CACHE_TAG_CONTENTS + textwrap.dedent("""
|
||||||
# For information about cache directory tags, see:
|
# This file is a cache directory tag created by Borg.
|
||||||
# http://www.bford.info/cachedir/spec.html
|
# For information about cache directory tags, see:
|
||||||
""").encode('ascii')
|
# http://www.bford.info/cachedir/spec.html
|
||||||
from ..platform import SaveFile
|
""").encode('ascii')
|
||||||
with SaveFile(cache_tag_fn, binary=True) as fd:
|
from ..platform import SaveFile
|
||||||
fd.write(cache_tag_contents)
|
with SaveFile(cache_tag_fn, binary=True) as fd:
|
||||||
|
fd.write(cache_tag_contents)
|
||||||
return cache_dir
|
return cache_dir
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue