From fb7a8f2d85b27324674cfa81db09effcda03bfbc Mon Sep 17 00:00:00 2001 From: William Bonnaventure Date: Sat, 13 Jul 2024 07:35:40 +0200 Subject: [PATCH] Add BORG_USE_CHUNKS_ARCHIVE option --- src/borg/cache.py | 5 +---- src/borg/testsuite/archiver/checks.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/borg/cache.py b/src/borg/cache.py index c36572c04..5394a2133 100644 --- a/src/borg/cache.py +++ b/src/borg/cache.py @@ -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): diff --git a/src/borg/testsuite/archiver/checks.py b/src/borg/testsuite/archiver/checks.py index 0fbf73439..51b3fe60e 100644 --- a/src/borg/testsuite/archiver/checks.py +++ b/src/borg/testsuite/archiver/checks.py @@ -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