Add BORG_USE_CHUNKS_ARCHIVE option

This commit is contained in:
William Bonnaventure 2024-07-13 07:35:40 +02:00
parent f5c9e2509f
commit fb7a8f2d85
2 changed files with 18 additions and 4 deletions

View File

@ -521,6 +521,7 @@ class LocalCache(CacheStatsMixin):
self.cache_mode = cache_mode
self.timestamp = None
self.txn_active = False
self.do_cache = os.environ.get("BORG_USE_CHUNKS_ARCHIVE", "yes").lower() in ["yes", "1", "true"]
self.path = cache_dir(self.repository, path)
self.security_manager = SecurityManager(self.repository)
@ -910,10 +911,6 @@ class LocalCache(CacheStatsMixin):
self.begin_txn()
with cache_if_remote(self.repository, decrypted_cache=self.repo_objs) as decrypted_repository:
# TEMPORARY HACK:
# to avoid archive index caching, create a FILE named ~/.cache/borg/REPOID/chunks.archive.d -
# this is only recommended if you have a fast, low latency connection to your repo (e.g. if repo is local).
self.do_cache = os.path.isdir(archive_path)
self.chunks = create_master_idx(self.chunks)
def check_cache_compatibility(self):

View File

@ -319,6 +319,23 @@ def test_check_cache(archivers, request):
check_cache(archiver)
def test_env_use_chunks_archive(archivers, request, monkeypatch):
archiver = request.getfixturevalue(archivers)
create_test_files(archiver.input_path)
monkeypatch.setenv("BORG_USE_CHUNKS_ARCHIVE", "no")
cmd(archiver, "rcreate", RK_ENCRYPTION)
repository_id = bin_to_hex(_extract_repository_id(archiver.repository_path))
cache_path = os.path.join(archiver.cache_path, repository_id)
cmd(archiver, "create", "test", "input")
assert os.path.exists(cache_path)
assert os.path.exists(os.path.join(cache_path, "chunks.archive.d"))
assert len(os.listdir(os.path.join(cache_path, "chunks.archive.d"))) == 0
cmd(archiver, "rdelete", "--cache-only")
monkeypatch.setenv("BORG_USE_CHUNKS_ARCHIVE", "yes")
cmd(archiver, "create", "test2", "input")
assert len(os.listdir(os.path.join(cache_path, "chunks.archive.d"))) > 0
# Begin Remote Tests
def test_remote_repo_restrict_to_path(remote_archiver):
original_location, repo_path = remote_archiver.repository_location, remote_archiver.repository_path