Преглед на файлове

Merge pull request #6962 from ThomasWaldmann/fixes-master

misc fixes / cleanups
TW преди 2 години
родител
ревизия
b392a60c08
променени са 4 файла, в които са добавени 25 реда и са изтрити 51 реда
  1. 5 24
      src/borg/archiver/common.py
  2. 1 1
      src/borg/archiver/create.py
  3. 0 9
      src/borg/archiver/keys.py
  4. 19 17
      src/borg/constants.py

+ 5 - 24
src/borg/archiver/common.py

@@ -27,15 +27,6 @@ from ..logger import create_logger
 logger = create_logger(__name__)
 
 
-def argument(args, str_or_bool):
-    """If bool is passed, return it. If str is passed, retrieve named attribute from args."""
-    if isinstance(str_or_bool, str):
-        return getattr(args, str_or_bool)
-    if isinstance(str_or_bool, (list, tuple)):
-        return any(getattr(args, item) for item in str_or_bool)
-    return str_or_bool
-
-
 def get_repository(location, *, create, exclusive, lock_wait, lock, append_only, make_parent_dirs, storage_quota, args):
     if location.proto == "ssh":
         repository = RemoteRepository(
@@ -80,24 +71,15 @@ def compat_check(*, create, manifest, key, cache, compatibility, decorator_name)
 
 
 def with_repository(
-    fake=False,
-    invert_fake=False,
-    create=False,
-    lock=True,
-    exclusive=False,
-    manifest=True,
-    cache=False,
-    secure=True,
-    compatibility=None,
+    create=False, lock=True, exclusive=False, manifest=True, cache=False, secure=True, compatibility=None
 ):
     """
     Method decorator for subcommand-handling methods: do_XYZ(self, args, repository, …)
 
     If a parameter (where allowed) is a str the attribute named of args is used instead.
-    :param fake: (str or bool) use None instead of repository, don't do anything else
     :param create: create repository
     :param lock: lock repository
-    :param exclusive: (str or bool) lock repository exclusively (for writing)
+    :param exclusive: (bool) lock repository exclusively (for writing)
     :param manifest: load manifest and key, pass them as keyword arguments
     :param cache: open cache, pass it as keyword argument (implies manifest)
     :param secure: do assert_secure after loading manifest
@@ -128,17 +110,16 @@ def with_repository(
             location = getattr(args, "location")
             if not location.valid:  # location always must be given
                 raise Error("missing repository, please use --repo or BORG_REPO env var!")
+            assert isinstance(exclusive, bool)
             lock = getattr(args, "lock", _lock)
             append_only = getattr(args, "append_only", False)
             storage_quota = getattr(args, "storage_quota", None)
             make_parent_dirs = getattr(args, "make_parent_dirs", False)
-            if argument(args, fake) ^ invert_fake:
-                return method(self, args, repository=None, **kwargs)
 
             repository = get_repository(
                 location,
                 create=create,
-                exclusive=argument(args, exclusive),
+                exclusive=exclusive,
                 lock_wait=self.lock_wait,
                 lock=lock,
                 append_only=append_only,
@@ -257,7 +238,7 @@ def with_archive(method):
             manifest,
             archive_name,
             numeric_ids=getattr(args, "numeric_ids", False),
-            noflags=getattr(args, "nobsdflags", False) or getattr(args, "noflags", False),
+            noflags=getattr(args, "noflags", False),
             noacls=getattr(args, "noacls", False),
             noxattrs=getattr(args, "noxattrs", False),
             cache=kwargs.get("cache"),

+ 1 - 1
src/borg/archiver/create.py

@@ -38,7 +38,7 @@ logger = create_logger()
 
 
 class CreateMixIn:
-    @with_repository(fake="dry_run", exclusive=True, compatibility=(Manifest.Operation.WRITE,))
+    @with_repository(exclusive=True, compatibility=(Manifest.Operation.WRITE,))
     def do_create(self, args, repository, manifest=None, key=None):
         """Create new archive"""
         matcher = PatternMatcher(fallback=True)

+ 0 - 9
src/borg/archiver/keys.py

@@ -89,15 +89,6 @@ class KeysMixIn:
 
         return EXIT_SUCCESS
 
-    @with_repository(exclusive=True, compatibility=(Manifest.Operation.CHECK,))
-    def do_change_algorithm(self, args, repository, manifest, key):
-        """Change repository key algorithm"""
-        if not hasattr(key, "change_passphrase"):
-            print("This repository is not encrypted, cannot change the algorithm.")
-            return EXIT_ERROR
-        key.save(key.target, key._passphrase, algorithm=KEY_ALGORITHMS[args.algorithm])
-        return EXIT_SUCCESS
-
     @with_repository(lock=False, exclusive=False, manifest=False, cache=False)
     def do_key_export(self, args, repository):
         """Export the repository key for backup"""

+ 19 - 17
src/borg/constants.py

@@ -30,15 +30,6 @@ UMASK_DEFAULT = 0o077
 # forcing to 0o100XXX later
 STDIN_MODE_DEFAULT = 0o660
 
-CACHE_TAG_NAME = "CACHEDIR.TAG"
-CACHE_TAG_CONTENTS = b"Signature: 8a477f597d28d172789f06886806bc55"
-
-# A large, but not unreasonably large segment size. Always less than 2 GiB (for legacy file systems). We choose
-# 500 MiB which means that no indirection from the inode is needed for typical Linux file systems.
-# Note that this is a soft-limit and can be exceeded (worst case) by a full maximum chunk size and some metadata
-# bytes. That's why it's 500 MiB instead of 512 MiB.
-DEFAULT_MAX_SEGMENT_SIZE = 500 * 1024 * 1024
-
 # in borg < 1.3, this has been defined like this:
 # 20 MiB minus 41 bytes for a PUT header (because the "size" field in the Repository includes
 # the header, and the total size was set to precisely 20 MiB for borg < 1.3).
@@ -49,12 +40,21 @@ MAX_DATA_SIZE = 20971479
 # borg < 1.3, but this is not expected to cause any issues.
 MAX_OBJECT_SIZE = MAX_DATA_SIZE + 41 + 8  # see assertion at end of repository module
 
-# how many metadata stream chunk ids do we store into a "pointer chunk" of the ArchiveItem.item_ptrs list?
-IDS_PER_CHUNK = 3  # MAX_DATA_SIZE // 40
+# How many segment files borg puts into a single directory by default.
+DEFAULT_SEGMENTS_PER_DIR = 1000
+
+# A large, but not unreasonably large segment size. Always less than 2 GiB (for legacy file systems). We choose
+# 500 MiB which means that no indirection from the inode is needed for typical Linux file systems.
+# Note that this is a soft-limit and can be exceeded (worst case) by a full maximum chunk size and some metadata
+# bytes. That's why it's 500 MiB instead of 512 MiB.
+DEFAULT_MAX_SEGMENT_SIZE = 500 * 1024 * 1024
 
 # repo config max_segment_size value must be below this limit to stay within uint32 offsets:
 MAX_SEGMENT_SIZE_LIMIT = 2**32 - MAX_OBJECT_SIZE
 
+# how many metadata stream chunk ids do we store into a "pointer chunk" of the ArchiveItem.item_ptrs list?
+IDS_PER_CHUNK = 3  # MAX_DATA_SIZE // 40
+
 # have one all-zero bytes object
 # we use it at all places where we need to detect or create all-zero buffers
 zeros = bytes(MAX_DATA_SIZE)
@@ -70,19 +70,18 @@ MAX_ARCHIVES = 400000
 # repo.list() / .scan() result count limit the borg client uses
 LIST_SCAN_LIMIT = 100000
 
-DEFAULT_SEGMENTS_PER_DIR = 1000
-
 FD_MAX_AGE = 4 * 60  # 4 minutes
 
+# chunker algorithms
+CH_BUZHASH = "buzhash"
+CH_FIXED = "fixed"
+
+# buzhash chunker params
 CHUNK_MIN_EXP = 19  # 2**19 == 512kiB
 CHUNK_MAX_EXP = 23  # 2**23 == 8MiB
 HASH_WINDOW_SIZE = 0xFFF  # 4095B
 HASH_MASK_BITS = 21  # results in ~2MiB chunks statistically
 
-# chunker algorithms
-CH_BUZHASH = "buzhash"
-CH_FIXED = "fixed"
-
 # defaults, use --chunker-params to override
 CHUNKER_PARAMS = (CH_BUZHASH, CHUNK_MIN_EXP, CHUNK_MAX_EXP, HASH_MASK_BITS, HASH_WINDOW_SIZE)
 
@@ -159,6 +158,9 @@ class KeyType:
     BLAKE2CHPOREPO = 0x41
 
 
+CACHE_TAG_NAME = "CACHEDIR.TAG"
+CACHE_TAG_CONTENTS = b"Signature: 8a477f597d28d172789f06886806bc55"
+
 REPOSITORY_README = """This is a Borg Backup repository.
 See https://borgbackup.readthedocs.io/
 """