浏览代码

cleanup: get rid of ignore_inode, replace with cache_mode

ignore_inode == ('i' not in cache_mode)  # i)node
Thomas Waldmann 7 年之前
父节点
当前提交
e2f71b5dc3
共有 3 个文件被更改,包括 12 次插入10 次删除
  1. 2 2
      src/borg/archive.py
  2. 3 3
      src/borg/archiver.py
  3. 7 5
      src/borg/cache.py

+ 2 - 2
src/borg/archive.py

@@ -1131,13 +1131,13 @@ class FilesystemObjectProcessors:
         self.add_item(item, stats=self.stats)
         self.add_item(item, stats=self.stats)
         return 'i'  # stdin
         return 'i'  # stdin
 
 
-    def process_file(self, path, st, cache, ignore_inode=False):
+    def process_file(self, path, st, cache):
         with self.create_helper(path, st, None) as (item, status, hardlinked, hardlink_master):  # no status yet
         with self.create_helper(path, st, None) as (item, status, hardlinked, hardlink_master):  # no status yet
             is_special_file = is_special(st.st_mode)
             is_special_file = is_special(st.st_mode)
             if not hardlinked or hardlink_master:
             if not hardlinked or hardlink_master:
                 if not is_special_file:
                 if not is_special_file:
                     path_hash = self.key.id_hash(safe_encode(os.path.join(self.cwd, path)))
                     path_hash = self.key.id_hash(safe_encode(os.path.join(self.cwd, path)))
-                    known, ids = cache.file_known_and_unchanged(path_hash, st, ignore_inode)
+                    known, ids = cache.file_known_and_unchanged(path_hash, st)
                 else:
                 else:
                     # in --read-special mode, we may be called for special files.
                     # in --read-special mode, we may be called for special files.
                     # there should be no information in the cache about special files processed in
                     # there should be no information in the cache about special files processed in

+ 3 - 3
src/borg/archiver.py

@@ -144,6 +144,7 @@ def with_repository(fake=False, invert_fake=False, create=False, lock=True,
                 if cache:
                 if cache:
                     with Cache(repository, kwargs['key'], kwargs['manifest'],
                     with Cache(repository, kwargs['key'], kwargs['manifest'],
                                do_files=getattr(args, 'cache_files', False),
                                do_files=getattr(args, 'cache_files', False),
+                               ignore_inode=getattr(args, 'ignore_inode', False),
                                progress=getattr(args, 'progress', False), lock_wait=self.lock_wait,
                                progress=getattr(args, 'progress', False), lock_wait=self.lock_wait,
                                cache_mode=getattr(args, 'files_cache_mode', DEFAULT_FILES_CACHE_MODE)) as cache_:
                                cache_mode=getattr(args, 'files_cache_mode', DEFAULT_FILES_CACHE_MODE)) as cache_:
                         return method(self, args, repository=repository, cache=cache_, **kwargs)
                         return method(self, args, repository=repository, cache=cache_, **kwargs)
@@ -502,7 +503,6 @@ class Archiver:
 
 
         self.output_filter = args.output_filter
         self.output_filter = args.output_filter
         self.output_list = args.output_list
         self.output_list = args.output_list
-        self.ignore_inode = args.ignore_inode
         self.nobsdflags = args.nobsdflags
         self.nobsdflags = args.nobsdflags
         self.exclude_nodump = args.exclude_nodump
         self.exclude_nodump = args.exclude_nodump
         dry_run = args.dry_run
         dry_run = args.dry_run
@@ -511,7 +511,7 @@ class Archiver:
         if not dry_run:
         if not dry_run:
             with Cache(repository, key, manifest, do_files=args.cache_files, progress=args.progress,
             with Cache(repository, key, manifest, do_files=args.cache_files, progress=args.progress,
                        lock_wait=self.lock_wait, permit_adhoc_cache=args.no_cache_sync,
                        lock_wait=self.lock_wait, permit_adhoc_cache=args.no_cache_sync,
-                       cache_mode=args.files_cache_mode) as cache:
+                       cache_mode=args.files_cache_mode, ignore_inode=args.ignore_inode) as cache:
                 archive = Archive(repository, key, manifest, args.location.archive, cache=cache,
                 archive = Archive(repository, key, manifest, args.location.archive, cache=cache,
                                   create=True, checkpoint_interval=args.checkpoint_interval,
                                   create=True, checkpoint_interval=args.checkpoint_interval,
                                   numeric_owner=args.numeric_owner, noatime=args.noatime, noctime=args.noctime,
                                   numeric_owner=args.numeric_owner, noatime=args.noatime, noctime=args.noctime,
@@ -577,7 +577,7 @@ class Archiver:
                         return
                         return
             if stat.S_ISREG(st.st_mode):
             if stat.S_ISREG(st.st_mode):
                 if not dry_run:
                 if not dry_run:
-                    status = fso.process_file(path, st, cache, self.ignore_inode)
+                    status = fso.process_file(path, st, cache)
             elif stat.S_ISDIR(st.st_mode):
             elif stat.S_ISDIR(st.st_mode):
                 if recurse:
                 if recurse:
                     tag_paths = dir_is_tagged(path, exclude_caches, exclude_if_present)
                     tag_paths = dir_is_tagged(path, exclude_caches, exclude_if_present)

+ 7 - 5
src/borg/cache.py

@@ -359,10 +359,13 @@ class Cache:
             shutil.rmtree(path)
             shutil.rmtree(path)
 
 
     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,
+                ignore_inode=False):
 
 
         if not do_files and 'd' not in cache_mode:
         if not do_files and 'd' not in cache_mode:
             cache_mode = 'd'
             cache_mode = 'd'
+        elif ignore_inode and 'i' in cache_mode:
+            cache_mode = ''.join(set(cache_mode) - set('i'))
 
 
         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,
@@ -924,14 +927,13 @@ class LocalCache(CacheStatsMixin):
         else:
         else:
             stats.update(-size, -csize, False)
             stats.update(-size, -csize, False)
 
 
-    def file_known_and_unchanged(self, path_hash, st, ignore_inode=False):
+    def file_known_and_unchanged(self, path_hash, st):
         """
         """
         Check if we know the file that has this path_hash (know == it is in our files cache) and
         Check if we know the file that has this path_hash (know == it is in our files cache) and
         whether it is unchanged (the size/inode number/cmtime is same for stuff we check in this cache_mode).
         whether it is unchanged (the size/inode number/cmtime is same for stuff we check in this cache_mode).
 
 
         :param path_hash: hash(file_path), to save some memory in the files cache
         :param path_hash: hash(file_path), to save some memory in the files cache
         :param st: the file's stat() result
         :param st: the file's stat() result
-        :param ignore_inode: whether the inode number shall be ignored
         :return: known, ids (known is True if we have infos about this file in the cache,
         :return: known, ids (known is True if we have infos about this file in the cache,
                              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).
         """
         """
@@ -950,7 +952,7 @@ class LocalCache(CacheStatsMixin):
         entry = FileCacheEntry(*msgpack.unpackb(entry))
         entry = FileCacheEntry(*msgpack.unpackb(entry))
         if 's' in cache_mode and entry.size != st.st_size:
         if 's' in cache_mode and entry.size != st.st_size:
             return True, None
             return True, None
-        if 'i' in cache_mode and not ignore_inode and entry.inode != st.st_ino:
+        if 'i' in cache_mode and entry.inode != st.st_ino:
             return True, None
             return True, None
         if 'c' in cache_mode and bigint_to_int(entry.cmtime) != st.st_ctime_ns:
         if 'c' in cache_mode and bigint_to_int(entry.cmtime) != st.st_ctime_ns:
             return True, None
             return True, None
@@ -1019,7 +1021,7 @@ Chunk index:    {0.total_unique_chunks:20d}             unknown"""
     files = None
     files = None
     cache_mode = 'd'
     cache_mode = 'd'
 
 
-    def file_known_and_unchanged(self, path_hash, st, ignore_inode=False):
+    def file_known_and_unchanged(self, path_hash, st):
         return False, None
         return False, None
 
 
     def memorize_file(self, path_hash, st, ids):
     def memorize_file(self, path_hash, st, ids):