From b8d49a0274db03ff4dcd4f3f800060496eab4e8a Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Wed, 17 May 2023 17:41:05 +0200 Subject: [PATCH] put security infos into data dir, fixes #5760 --- src/borg/helpers/fs.py | 15 ++++++++++++++- src/borg/testsuite/helpers.py | 10 ++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/borg/helpers/fs.py b/src/borg/helpers/fs.py index af7297095..80e62c403 100644 --- a/src/borg/helpers/fs.py +++ b/src/borg/helpers/fs.py @@ -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""" diff --git a/src/borg/testsuite/helpers.py b/src/borg/testsuite/helpers.py index bfb4f5c32..eba51b311 100644 --- a/src/borg/testsuite/helpers.py +++ b/src/borg/testsuite/helpers.py @@ -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"