borgbackup/borg

View on GitHub

Showing 611 of 611 total issues

Similar blocks of code found in 4 locations. Consider refactoring.
Open

    if archiver.FORK_DEFAULT:
        expected_ec = RepoIdMismatch().exit_code
        cmd(archiver, "key", "import", export_file, exit_code=expected_ec)
    else:
        with pytest.raises(RepoIdMismatch):
Severity: Major
Found in src/borg/testsuite/archiver/key_cmds_test.py and 3 other locations - About 2 hrs to fix
src/borg/testsuite/archiver/key_cmds_test.py on lines 173..178
src/borg/testsuite/archiver/key_cmds_test.py on lines 198..203
src/borg/testsuite/archiver/key_cmds_test.py on lines 208..213

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 50.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 4 locations. Consider refactoring.
Open

    if archiver.FORK_DEFAULT:
        expected_ec = CommandError().exit_code
        cmd(archiver, "key", "export", export_directory, exit_code=expected_ec)
    else:
        with pytest.raises(CommandError):
Severity: Major
Found in src/borg/testsuite/archiver/key_cmds_test.py and 3 other locations - About 2 hrs to fix
src/borg/testsuite/archiver/key_cmds_test.py on lines 198..203
src/borg/testsuite/archiver/key_cmds_test.py on lines 208..213
src/borg/testsuite/archiver/key_cmds_test.py on lines 218..223

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 50.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 4 locations. Consider refactoring.
Open

    if archiver.FORK_DEFAULT:
        expected_ec = CommandError().exit_code
        cmd(archiver, "key", "import", export_file, exit_code=expected_ec)
    else:
        with pytest.raises(CommandError):
Severity: Major
Found in src/borg/testsuite/archiver/key_cmds_test.py and 3 other locations - About 2 hrs to fix
src/borg/testsuite/archiver/key_cmds_test.py on lines 173..178
src/borg/testsuite/archiver/key_cmds_test.py on lines 208..213
src/borg/testsuite/archiver/key_cmds_test.py on lines 218..223

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 50.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Function daemonizing has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

def daemonizing(*, timeout=5):
    """Like daemonize(), but as context manager.

    The with-body is executed in the background process,
    while the foreground process survives until the body is left
Severity: Minor
Found in src/borg/helpers/process.py - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function rebuild_archives_directory has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

    def rebuild_archives_directory(self):
        """Rebuild the archives directory, undeleting archives.

        Iterates through all objects in the repository looking for archive metadata blocks.
        When finding some that do not have a corresponding archives directory entry, it will
Severity: Minor
Found in src/borg/archive.py - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function test_prune_quarterly has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

def test_prune_quarterly(archivers, request):
    # Example worked through by hand when developing quarterly
    # strategy, based upon existing backups where quarterly strategy
    # is desired. Weekly/monthly backups that don't affect results were
    # trimmed to speed up the test.
Severity: Minor
Found in src/borg/testsuite/archiver/prune_cmd_test.py - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function resolve has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

        def resolve(self, args: argparse.Namespace):  # Namespace has "in" but otherwise is not like a dict.
            """
            Resolve the multiple definitions of each common option to the final value.
            """
            for suffix in self.suffix_precedence:
Severity: Minor
Found in src/borg/archiver/__init__.py - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function do_repo_space has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

    def do_repo_space(self, args, repository):
        """Manage reserved space in repository"""
        # we work without locking here because locks don't work with full disk.
        if args.reserve_space > 0:
            storage_space_reserve_object_size = 64 * 2**20  # 64 MiB per object
Severity: Minor
Found in src/borg/archiver/repo_space_cmd.py - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function load has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

    def load(self):
        try:
            with open(self.path) as f:
                data = json.load(f)

Severity: Minor
Found in src/borg/fslocking.py - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function _build_files_cache has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

    def _build_files_cache(self):
        """rebuild the files cache by reading previous archive from repository"""
        if "d" in self.cache_mode:  # d(isabled)
            return

Severity: Minor
Found in src/borg/cache.py - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function _rec_walk has 15 arguments (exceeds 4 allowed). Consider refactoring.
Open

    def _rec_walk(
Severity: Major
Found in src/borg/archiver/create_cmd.py - About 1 hr to fix

    Identical blocks of code found in 3 locations. Consider refactoring.
    Open

        with Repository(archiver.repository_path) as repository:
            key = msgpack.unpackb(binascii.a2b_base64(repository.load_key()))
            assert key["algorithm"] == "argon2 chacha20-poly1305"
    Severity: Major
    Found in src/borg/testsuite/archiver/key_cmds_test.py and 2 other locations - About 1 hr to fix
    src/borg/testsuite/archiver/key_cmds_test.py on lines 305..307
    src/borg/testsuite/archiver/key_cmds_test.py on lines 326..328

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 48.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Identical blocks of code found in 3 locations. Consider refactoring.
    Open

        with Repository(archiver.repository_path) as repository:
            key = msgpack.unpackb(binascii.a2b_base64(repository.load_key()))
            assert key["algorithm"] == "argon2 chacha20-poly1305"
    Severity: Major
    Found in src/borg/testsuite/archiver/key_cmds_test.py and 2 other locations - About 1 hr to fix
    src/borg/testsuite/archiver/key_cmds_test.py on lines 305..307
    src/borg/testsuite/archiver/key_cmds_test.py on lines 316..318

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 48.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Identical blocks of code found in 3 locations. Consider refactoring.
    Open

        with Repository(archiver.repository_path) as repository:
            key = msgpack.unpackb(binascii.a2b_base64(repository.load_key()))
            assert key["algorithm"] == "argon2 chacha20-poly1305"
    Severity: Major
    Found in src/borg/testsuite/archiver/key_cmds_test.py and 2 other locations - About 1 hr to fix
    src/borg/testsuite/archiver/key_cmds_test.py on lines 316..318
    src/borg/testsuite/archiver/key_cmds_test.py on lines 326..328

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 48.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Function build_parser has 44 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def build_parser(self):
            from ._common import define_common_options
    
            parser = argparse.ArgumentParser(prog=self.prog, description="Borg - Deduplicated Backups", add_help=False)
            # paths and patterns must have an empty list as default everywhere
    Severity: Minor
    Found in src/borg/archiver/__init__.py - About 1 hr to fix

      Function detect has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          def detect(cls, repository, manifest_data):
              key = cls(repository)
              target = key.find_key()
              prompt = "Enter passphrase for key %s: " % target
              passphrase = Passphrase.env_passphrase()
      Severity: Minor
      Found in src/borg/crypto/key.py - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function upgrade_item has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          def upgrade_item(self, *, item):
              """upgrade item as needed, get rid of legacy crap"""
              ITEM_KEY_WHITELIST = {
                  "path",
                  "rdev",
      Severity: Minor
      Found in src/borg/upgrade.py - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function _matching_info_tuples has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          def _matching_info_tuples(self, match_patterns, match_end):
              archive_infos = list(self._info_tuples())
              if match_patterns:
                  assert isinstance(match_patterns, list), f"match_pattern is a {type(match_patterns)}"
                  for match in match_patterns:
      Severity: Minor
      Found in src/borg/manifest.py - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function __init__ has 14 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def __init__(
      Severity: Major
      Found in src/borg/archive.py - About 1 hr to fix

        Function save_config has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

            def save_config(self, path, config):
                config_path = os.path.join(path, "config")
                old_config_path = os.path.join(path, "config.old")
        
                if os.path.isfile(old_config_path):
        Severity: Minor
        Found in src/borg/legacyrepository.py - About 1 hr to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Severity
        Category
        Status
        Source
        Language