diff --git a/docs/usage/general/environment.rst.inc b/docs/usage/general/environment.rst.inc index cd32e09b9..b386dc465 100644 --- a/docs/usage/general/environment.rst.inc +++ b/docs/usage/general/environment.rst.inc @@ -89,11 +89,13 @@ General: - ``local``: uses a persistent chunks cache and keeps it in a perfect state (precise refcounts and sizes), requiring a potentially resource expensive cache sync in multi-client scenarios. - Also has a persistent files cache. Default implementation. + Also has a persistent files cache. - ``adhoc``: builds a non-persistent chunks cache by querying the repo. Chunks cache contents are somewhat sloppy for already existing chunks, concerning their refcount ("infinite") and size (0). No files cache (slow, will chunk all input files). DEPRECATED. - - ``adhocwithfiles``: Like ``adhoc``, but with a persistent files cache. + - ``adhocwithfiles``: Like ``adhoc``, but with a persistent files cache. Default implementation. + - ``cli``: Determine the cache implementation from cli options. Without special options, will + usually end up with the ``local`` implementation. BORG_SELFTEST This can be used to influence borg's builtin self-tests. The default is to execute the tests at the beginning of each borg command invocation. diff --git a/src/borg/cache.py b/src/borg/cache.py index 4836314d4..88fe32902 100644 --- a/src/borg/cache.py +++ b/src/borg/cache.py @@ -299,6 +299,10 @@ class CacheConfig: raise Exception("%s does not look like a Borg cache." % config_path) from None +def get_cache_impl(): + return os.environ.get("BORG_CACHE_IMPL", "adhocwithfiles") + + class Cache: """Client Side cache""" @@ -382,8 +386,8 @@ class Cache: def adhoc(): return AdHocCache(manifest=manifest, lock_wait=lock_wait, iec=iec) - impl = os.environ.get("BORG_CACHE_IMPL", None) - if impl is not None: + impl = get_cache_impl() + if impl != "cli": methods = dict(local=local, adhocwithfiles=adhocwithfiles, adhoc=adhoc) try: method = methods[impl] diff --git a/src/borg/testsuite/archiver/checks.py b/src/borg/testsuite/archiver/checks.py index c095762e6..a9324fbdf 100644 --- a/src/borg/testsuite/archiver/checks.py +++ b/src/borg/testsuite/archiver/checks.py @@ -4,7 +4,7 @@ from unittest.mock import patch import pytest -from ...cache import Cache, LocalCache +from ...cache import Cache, LocalCache, get_cache_impl from ...constants import * # NOQA from ...helpers import Location, get_security_dir, bin_to_hex from ...helpers import EXIT_ERROR @@ -204,9 +204,7 @@ def test_unknown_feature_on_create(archivers, request): cmd_raises_unknown_feature(archiver, ["create", "test", "input"]) -@pytest.mark.skipif( - os.environ.get("BORG_CACHE_IMPL") in ("adhocwithfiles", "adhoc"), reason="only works with LocalCache" -) +@pytest.mark.skipif(get_cache_impl() in ("adhocwithfiles", "adhoc"), reason="only works with LocalCache") def test_unknown_feature_on_cache_sync(archivers, request): # LocalCache.sync checks repo compat archiver = request.getfixturevalue(archivers) @@ -326,9 +324,7 @@ def test_check_cache(archivers, request): check_cache(archiver) -@pytest.mark.skipif( - os.environ.get("BORG_CACHE_IMPL") in ("adhocwithfiles", "adhoc"), reason="only works with LocalCache" -) +@pytest.mark.skipif(get_cache_impl() in ("adhocwithfiles", "adhoc"), reason="only works with LocalCache") def test_env_use_chunks_archive(archivers, request, monkeypatch): archiver = request.getfixturevalue(archivers) create_test_files(archiver.input_path) diff --git a/src/borg/testsuite/archiver/create_cmd.py b/src/borg/testsuite/archiver/create_cmd.py index 461097ac5..4d7626d2b 100644 --- a/src/borg/testsuite/archiver/create_cmd.py +++ b/src/borg/testsuite/archiver/create_cmd.py @@ -12,6 +12,7 @@ import time import pytest from ... import platform +from ...cache import get_cache_impl from ...constants import * # NOQA from ...manifest import Manifest from ...platform import is_cygwin, is_win32, is_darwin @@ -540,9 +541,7 @@ def test_create_pattern_intermediate_folders_first(archivers, request): assert out_list.index("d x/b") < out_list.index("- x/b/foo_b") -@pytest.mark.skipif( - os.environ.get("BORG_CACHE_IMPL") in ("adhocwithfiles", "local"), reason="only works with AdHocCache" -) +@pytest.mark.skipif(get_cache_impl() in ("adhocwithfiles", "local"), reason="only works with AdHocCache") def test_create_no_cache_sync_adhoc(archivers, request): # TODO: add test for AdHocWithFilesCache archiver = request.getfixturevalue(archivers) create_test_files(archiver.input_path)