Browse Source

Add BORG_USE_CHUNKS_ARCHIVE option

William Bonnaventure 11 months ago
parent
commit
0575f87580
2 changed files with 16 additions and 3 deletions
  1. 1 3
      src/borg/cache.py
  2. 15 0
      src/borg/testsuite/archiver.py

+ 1 - 3
src/borg/cache.py

@@ -478,6 +478,7 @@ class LocalCache(CacheStatsMixin):
         self.consider_part_files = consider_part_files
         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(repository, path)
         self.security_manager = SecurityManager(repository)
@@ -907,9 +908,6 @@ class LocalCache(CacheStatsMixin):
         self.begin_txn()
         with cache_if_remote(self.repository, decrypted_cache=self.key) as decrypted_repository:
             legacy_cleanup()
-            # 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 disk)
-            self.do_cache = os.path.isdir(archive_path)
             self.chunks = create_master_idx(self.chunks)
 
     def check_cache_compatibility(self):

+ 15 - 0
src/borg/testsuite/archiver.py

@@ -3075,6 +3075,21 @@ class ArchiverTestCase(ArchiverTestCaseBase):
         with pytest.raises(AssertionError):
             self.check_cache()
 
+    def test_env_use_chunks_archive(self):
+        self.create_test_files()
+        with environment_variable(BORG_USE_CHUNKS_ARCHIVE="no"):
+            self.cmd("init", "--encryption=repokey", self.repository_location)
+            self.cmd("create", self.repository_location + "::test", "input")
+        repository_id = bin_to_hex(self._extract_repository_id(self.repository_path))
+        cache_path = os.path.join(self.cache_path, repository_id)
+        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
+        self.cmd("delete", self.repository_location, "--cache-only")
+        with environment_variable(BORG_USE_CHUNKS_ARCHIVE="yes"):
+            self.cmd("create", self.repository_location + "::test2", "input")
+        assert len(os.listdir(os.path.join(cache_path, "chunks.archive.d"))) > 0
+
     def test_recreate_target_rc(self):
         self.cmd('init', '--encryption=repokey', self.repository_location)
         if self.FORK_DEFAULT: