mirror of https://github.com/borgbackup/borg.git
use XDG_CONFIG_HOME for borg keys instead of ~/.borg, fixes #515
This commit is contained in:
parent
824e548b9f
commit
b8d954e60a
|
@ -210,8 +210,8 @@ class Statistics:
|
|||
|
||||
def get_keys_dir():
|
||||
"""Determine where to repository keys and cache"""
|
||||
return os.environ.get('BORG_KEYS_DIR',
|
||||
os.path.join(os.path.expanduser('~'), '.borg', 'keys'))
|
||||
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'))
|
||||
|
||||
|
||||
def get_cache_dir():
|
||||
|
|
|
@ -10,7 +10,8 @@ import msgpack
|
|||
import msgpack.fallback
|
||||
|
||||
from ..helpers import Location, format_file_size, format_timedelta, make_path_safe, \
|
||||
prune_within, prune_split, get_cache_dir, Statistics, is_slow_msgpack, yes, TRUISH, FALSISH, DEFAULTISH, \
|
||||
prune_within, prune_split, get_cache_dir, get_keys_dir, Statistics, is_slow_msgpack, \
|
||||
yes, TRUISH, FALSISH, DEFAULTISH, \
|
||||
StableDict, int_to_bigint, bigint_to_int, parse_timestamp, CompressionSpec, ChunkerParams, \
|
||||
ProgressIndicatorPercent, ProgressIndicatorEndless, load_excludes, parse_pattern, \
|
||||
PatternMatcher, RegexPattern, PathPrefixPattern, FnmatchPattern, ShellPattern
|
||||
|
@ -579,7 +580,7 @@ class TestParseTimestamp(BaseTestCase):
|
|||
|
||||
|
||||
def test_get_cache_dir():
|
||||
"""test that get_cache_dir respects environement"""
|
||||
"""test that get_cache_dir respects environment"""
|
||||
# reset BORG_CACHE_DIR in order to test default
|
||||
old_env = None
|
||||
if os.environ.get('BORG_CACHE_DIR'):
|
||||
|
@ -595,6 +596,23 @@ def test_get_cache_dir():
|
|||
os.environ['BORG_CACHE_DIR'] = old_env
|
||||
|
||||
|
||||
def test_get_keys_dir():
|
||||
"""test that get_keys_dir respects environment"""
|
||||
# reset BORG_KEYS_DIR in order to test default
|
||||
old_env = None
|
||||
if os.environ.get('BORG_KEYS_DIR'):
|
||||
old_env = os.environ['BORG_KEYS_DIR']
|
||||
del(os.environ['BORG_KEYS_DIR'])
|
||||
assert get_keys_dir() == os.path.join(os.path.expanduser('~'), '.config', 'borg', 'keys')
|
||||
os.environ['XDG_CONFIG_HOME'] = '/var/tmp/.config'
|
||||
assert get_keys_dir() == os.path.join('/var/tmp/.config', 'borg', 'keys')
|
||||
os.environ['BORG_KEYS_DIR'] = '/var/tmp'
|
||||
assert get_keys_dir() == '/var/tmp'
|
||||
# reset old env
|
||||
if old_env is not None:
|
||||
os.environ['BORG_KEYS_DIR'] = old_env
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def stats():
|
||||
stats = Statistics()
|
||||
|
|
Loading…
Reference in New Issue