Quellcode durchsuchen

BORG_CACHE_IMPL defaults to "adhocwithfiles" now

Also: support a "cli" env var value, that does not determine
the implementation from the env var, but rather from cli options (similar to as it was before adding BORG_CACHE_IMPL).
Thomas Waldmann vor 10 Monaten
Ursprung
Commit
619a06a5ba

+ 4 - 2
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.

+ 6 - 2
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]

+ 3 - 7
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)

+ 2 - 3
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)