mirror of
https://github.com/borgbackup/borg.git
synced 2026-02-15 08:38:18 -05:00
put security infos into data dir, fixes #5760
This commit is contained in:
parent
852172f5ce
commit
b8d49a0274
2 changed files with 20 additions and 5 deletions
|
|
@ -85,14 +85,27 @@ def get_security_dir(repository_id=None, *, legacy=False):
|
|||
"""Determine where to store local security information."""
|
||||
security_dir = os.environ.get("BORG_SECURITY_DIR")
|
||||
if security_dir is None:
|
||||
get_dir = get_config_dir if legacy else get_data_dir
|
||||
# note: do not just give this as default to the environment.get(), see issue #5979.
|
||||
security_dir = os.path.join(get_config_dir(legacy=legacy), "security")
|
||||
security_dir = os.path.join(get_dir(legacy=legacy), "security")
|
||||
if repository_id:
|
||||
security_dir = os.path.join(security_dir, repository_id)
|
||||
ensure_dir(security_dir)
|
||||
return security_dir
|
||||
|
||||
|
||||
def get_data_dir(*, legacy=False):
|
||||
"""Determine where to store borg changing data on the client"""
|
||||
assert legacy is False, "there is no legacy variant of the borg data dir"
|
||||
data_dir = os.environ.get(
|
||||
"BORG_DATA_DIR", join_base_dir(".local", "share", "borg", legacy=legacy) or platformdirs.user_data_dir("borg")
|
||||
)
|
||||
|
||||
# Create path if it doesn't exist yet
|
||||
ensure_dir(data_dir)
|
||||
return data_dir
|
||||
|
||||
|
||||
def get_cache_dir(*, legacy=False):
|
||||
"""Determine where to repository keys and cache"""
|
||||
|
||||
|
|
|
|||
|
|
@ -740,11 +740,13 @@ def test_get_security_dir(monkeypatch):
|
|||
monkeypatch.setenv("BORG_SECURITY_DIR", "/var/tmp")
|
||||
assert get_security_dir() == "/var/tmp"
|
||||
else:
|
||||
monkeypatch.delenv("XDG_CONFIG_HOME", raising=False)
|
||||
monkeypatch.delenv("XDG_DATA_HOME", raising=False)
|
||||
monkeypatch.delenv("BORG_SECURITY_DIR", raising=False)
|
||||
assert get_security_dir() == os.path.join(home_dir, ".config", "borg", "security")
|
||||
assert get_security_dir(repository_id="1234") == os.path.join(home_dir, ".config", "borg", "security", "1234")
|
||||
monkeypatch.setenv("XDG_CONFIG_HOME", "/var/tmp/.config")
|
||||
assert get_security_dir() == os.path.join(home_dir, ".local", "share", "borg", "security")
|
||||
assert get_security_dir(repository_id="1234") == os.path.join(
|
||||
home_dir, ".local", "share", "borg", "security", "1234"
|
||||
)
|
||||
monkeypatch.setenv("XDG_DATA_HOME", "/var/tmp/.config")
|
||||
assert get_security_dir() == os.path.join("/var/tmp/.config", "borg", "security")
|
||||
monkeypatch.setenv("BORG_SECURITY_DIR", "/var/tmp")
|
||||
assert get_security_dir() == "/var/tmp"
|
||||
|
|
|
|||
Loading…
Reference in a new issue