From 9c9ac2fd58d3217ae431db96a5dd1196d09be99a Mon Sep 17 00:00:00 2001 From: Teemu Toivanen Date: Mon, 29 Feb 2016 21:47:26 +0200 Subject: [PATCH] Remote end does not need cache nor keys directories, do not make them. Move keys and cache creation to get_keys_dir and get_cache_dir helper functions. And remove keys_dir and cache_dir from run(). cache and keys will only be created by code which uses them. Remote end should not call get_keys_dir and get_cache_dir --- borg/archiver.py | 17 +---------------- borg/helpers.py | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/borg/archiver.py b/borg/archiver.py index 6bc9103ff..aa6056a68 100644 --- a/borg/archiver.py +++ b/borg/archiver.py @@ -17,7 +17,7 @@ from . import __version__ from .helpers import Error, location_validator, archivename_validator, format_line, format_time, format_file_size, \ parse_pattern, PathPrefixPattern, to_localtime, timestamp, safe_timestamp, \ - get_cache_dir, get_keys_dir, prune_within, prune_split, \ + get_cache_dir, prune_within, prune_split, \ Manifest, remove_surrogates, update_excludes, format_archive, check_extension_modules, Statistics, \ dir_is_tagged, bigint_to_int, ChunkerParams, CompressionSpec, is_slow_msgpack, yes, sysinfo, \ EXIT_SUCCESS, EXIT_WARNING, EXIT_ERROR, log_multi, PatternMatcher @@ -1415,21 +1415,6 @@ def run(self, args): self.lock_wait = args.lock_wait setup_logging(level=args.log_level, is_serve=args.func == self.do_serve) # do not use loggers before this! check_extension_modules() - keys_dir = get_keys_dir() - if not os.path.exists(keys_dir): - os.makedirs(keys_dir) - os.chmod(keys_dir, stat.S_IRWXU) - cache_dir = get_cache_dir() - if not os.path.exists(cache_dir): - os.makedirs(cache_dir) - os.chmod(cache_dir, stat.S_IRWXU) - with open(os.path.join(cache_dir, 'CACHEDIR.TAG'), 'w') as fd: - fd.write(textwrap.dedent(""" - Signature: 8a477f597d28d172789f06886806bc55 - # This file is a cache directory tag created by Borg. - # For information about cache directory tags, see: - # http://www.brynosaurus.com/cachedir/ - """).lstrip()) if is_slow_msgpack(): logger.warning("Using a pure-python msgpack! This will result in lower performance.") return args.func(args) diff --git a/borg/helpers.py b/borg/helpers.py index b8bd8e170..3132cd06c 100644 --- a/borg/helpers.py +++ b/borg/helpers.py @@ -3,6 +3,8 @@ from functools import wraps import grp import os +import stat +import textwrap import pwd import re from shutil import get_terminal_size @@ -211,13 +213,28 @@ def show_progress(self, item=None, final=False, stream=None, dt=None): def get_keys_dir(): """Determine where to repository keys and cache""" xdg_config = os.environ.get('XDG_CONFIG_HOME', os.path.join(os.path.expanduser('~'), '.config')) - return os.environ.get('BORG_KEYS_DIR', os.path.join(xdg_config, 'borg', 'keys')) + keys_dir = os.environ.get('BORG_KEYS_DIR', os.path.join(xdg_config, 'borg', 'keys')) + if not os.path.exists(keys_dir): + os.makedirs(keys_dir) + os.chmod(keys_dir, stat.S_IRWXU) + return keys_dir def get_cache_dir(): """Determine where to repository keys and cache""" xdg_cache = os.environ.get('XDG_CACHE_HOME', os.path.join(os.path.expanduser('~'), '.cache')) - return os.environ.get('BORG_CACHE_DIR', os.path.join(xdg_cache, 'borg')) + cache_dir = os.environ.get('BORG_CACHE_DIR', os.path.join(xdg_cache, 'borg')) + if not os.path.exists(cache_dir): + os.makedirs(cache_dir) + os.chmod(cache_dir, stat.S_IRWXU) + with open(os.path.join(cache_dir, 'CACHEDIR.TAG'), 'w') as fd: + fd.write(textwrap.dedent(""" + Signature: 8a477f597d28d172789f06886806bc55 + # This file is a cache directory tag created by Borg. + # For information about cache directory tags, see: + # http://www.brynosaurus.com/cachedir/ + """).lstrip()) + return cache_dir def to_localtime(ts):