Browse Source

cleanup: get rid of Cache.do_files, replace with cache_mode

not do_files == (cache_mode == 'd')  # d)isabled
Thomas Waldmann 7 years ago
parent
commit
b1e7e7f90a
4 changed files with 13 additions and 11 deletions
  1. 1 1
      src/borg/archive.py
  2. 1 1
      src/borg/archiver.py
  3. 10 8
      src/borg/cache.py
  4. 1 1
      src/borg/testsuite/cache.py

+ 1 - 1
src/borg/archive.py

@@ -1144,7 +1144,7 @@ class FilesystemObjectProcessors:
                     # read-special mode, but we better play safe as this was wrong in the past:
                     # read-special mode, but we better play safe as this was wrong in the past:
                     path_hash = None
                     path_hash = None
                     known, ids = False, None
                     known, ids = False, None
-                first_run = not cache.files and cache.do_files
+                first_run = not cache.files and 'd' not in cache.cache_mode
                 if first_run:
                 if first_run:
                     logger.debug('Processing files ...')
                     logger.debug('Processing files ...')
                 chunks = None
                 chunks = None

+ 1 - 1
src/borg/archiver.py

@@ -1347,7 +1347,7 @@ class Archiver:
 
 
         to_delete = (set(archives) | checkpoints) - (set(keep) | set(keep_checkpoints))
         to_delete = (set(archives) | checkpoints) - (set(keep) | set(keep_checkpoints))
         stats = Statistics()
         stats = Statistics()
-        with Cache(repository, key, manifest, do_files=False, lock_wait=self.lock_wait) as cache:
+        with Cache(repository, key, manifest, lock_wait=self.lock_wait) as cache:
             list_logger = logging.getLogger('borg.output.list')
             list_logger = logging.getLogger('borg.output.list')
             # set up counters for the progress display
             # set up counters for the progress display
             to_delete_len = len(to_delete)
             to_delete_len = len(to_delete)

+ 10 - 8
src/borg/cache.py

@@ -360,9 +360,13 @@ class Cache:
 
 
     def __new__(cls, repository, key, manifest, path=None, sync=True, do_files=False, warn_if_unencrypted=True,
     def __new__(cls, repository, key, manifest, path=None, sync=True, do_files=False, warn_if_unencrypted=True,
                 progress=False, lock_wait=None, permit_adhoc_cache=False, cache_mode=DEFAULT_FILES_CACHE_MODE):
                 progress=False, lock_wait=None, permit_adhoc_cache=False, cache_mode=DEFAULT_FILES_CACHE_MODE):
+
+        if not do_files and 'd' not in cache_mode:
+            cache_mode = 'd'
+
         def local():
         def local():
             return LocalCache(repository=repository, key=key, manifest=manifest, path=path, sync=sync,
             return LocalCache(repository=repository, key=key, manifest=manifest, path=path, sync=sync,
-                              do_files=do_files, warn_if_unencrypted=warn_if_unencrypted, progress=progress,
+                              warn_if_unencrypted=warn_if_unencrypted, progress=progress,
                               lock_wait=lock_wait, cache_mode=cache_mode)
                               lock_wait=lock_wait, cache_mode=cache_mode)
 
 
         def adhoc():
         def adhoc():
@@ -421,10 +425,9 @@ class LocalCache(CacheStatsMixin):
     Persistent, local (client-side) cache.
     Persistent, local (client-side) cache.
     """
     """
 
 
-    def __init__(self, repository, key, manifest, path=None, sync=True, do_files=False, warn_if_unencrypted=True,
+    def __init__(self, repository, key, manifest, path=None, sync=True, warn_if_unencrypted=True,
                  progress=False, lock_wait=None, cache_mode=DEFAULT_FILES_CACHE_MODE):
                  progress=False, lock_wait=None, cache_mode=DEFAULT_FILES_CACHE_MODE):
         """
         """
-        :param do_files: use file metadata cache
         :param warn_if_unencrypted: print warning if accessing unknown unencrypted repository
         :param warn_if_unencrypted: print warning if accessing unknown unencrypted repository
         :param lock_wait: timeout for lock acquisition (None: return immediately if lock unavailable)
         :param lock_wait: timeout for lock acquisition (None: return immediately if lock unavailable)
         :param sync: do :meth:`.sync`
         :param sync: do :meth:`.sync`
@@ -434,7 +437,6 @@ class LocalCache(CacheStatsMixin):
         self.key = key
         self.key = key
         self.manifest = manifest
         self.manifest = manifest
         self.progress = progress
         self.progress = progress
-        self.do_files = do_files
         self.cache_mode = cache_mode
         self.cache_mode = cache_mode
         self.timestamp = None
         self.timestamp = None
         self.txn_active = False
         self.txn_active = False
@@ -487,7 +489,7 @@ class LocalCache(CacheStatsMixin):
         with IntegrityCheckedFile(path=os.path.join(self.path, 'chunks'), write=False,
         with IntegrityCheckedFile(path=os.path.join(self.path, 'chunks'), write=False,
                                   integrity_data=self.cache_config.integrity.get('chunks')) as fd:
                                   integrity_data=self.cache_config.integrity.get('chunks')) as fd:
             self.chunks = ChunkIndex.read(fd)
             self.chunks = ChunkIndex.read(fd)
-        if 'd' in self.cache_mode or not self.do_files:  # d(isabled)
+        if 'd' in self.cache_mode:  # d(isabled)
             self.files = None
             self.files = None
         else:
         else:
             self._read_files()
             self._read_files()
@@ -934,7 +936,7 @@ class LocalCache(CacheStatsMixin):
                              ids is the list of chunk ids IF the file has not changed, otherwise None).
                              ids is the list of chunk ids IF the file has not changed, otherwise None).
         """
         """
         cache_mode = self.cache_mode
         cache_mode = self.cache_mode
-        if 'd' in cache_mode or not self.do_files or not stat.S_ISREG(st.st_mode):  # d(isabled)
+        if 'd' in cache_mode or not stat.S_ISREG(st.st_mode):  # d(isabled)
             return False, None
             return False, None
         # note: r(echunk) does not need the files cache in this method, but the files cache will
         # note: r(echunk) does not need the files cache in this method, but the files cache will
         # be updated and saved to disk to memorize the files. To preserve previous generations in
         # be updated and saved to disk to memorize the files. To preserve previous generations in
@@ -968,7 +970,7 @@ class LocalCache(CacheStatsMixin):
     def memorize_file(self, path_hash, st, ids):
     def memorize_file(self, path_hash, st, ids):
         cache_mode = self.cache_mode
         cache_mode = self.cache_mode
         # note: r(echunk) modes will update the files cache, d(isabled) mode won't
         # note: r(echunk) modes will update the files cache, d(isabled) mode won't
-        if 'd' in cache_mode or not self.do_files or not stat.S_ISREG(st.st_mode):
+        if 'd' in cache_mode or not stat.S_ISREG(st.st_mode):
             return
             return
         if 'c' in cache_mode:
         if 'c' in cache_mode:
             cmtime_ns = safe_ns(st.st_ctime_ns)
             cmtime_ns = safe_ns(st.st_ctime_ns)
@@ -1015,7 +1017,7 @@ Chunk index:    {0.total_unique_chunks:20d}             unknown"""
         pass
         pass
 
 
     files = None
     files = None
-    do_files = False
+    cache_mode = 'd'
 
 
     def file_known_and_unchanged(self, path_hash, st, ignore_inode=False):
     def file_known_and_unchanged(self, path_hash, st, ignore_inode=False):
         return False, None
         return False, None

+ 1 - 1
src/borg/testsuite/cache.py

@@ -257,7 +257,7 @@ class TestAdHocCache:
 
 
     def test_files_cache(self, cache):
     def test_files_cache(self, cache):
         assert cache.file_known_and_unchanged(bytes(32), None) == (False, None)
         assert cache.file_known_and_unchanged(bytes(32), None) == (False, None)
-        assert not cache.do_files
+        assert cache.cache_mode == 'd'
         assert cache.files is None
         assert cache.files is None
 
 
     def test_txn(self, cache):
     def test_txn(self, cache):