borgbackup/borg

View on GitHub

Showing 611 of 611 total issues

Function exec_cmd has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

def exec_cmd(*args, archiver=None, fork=False, exe=None, input=b"", binary_output=False, **kw):
    if fork:
        try:
            if exe is None:
                borg = (sys.executable, "-m", "borg")
Severity: Minor
Found in src/borg/testsuite/archiver/__init__.py - About 3 hrs 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 _process_leaf has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

    def _process_leaf(self, name, item, parent, prefix, is_dir, item_inode, hlm):
        path = item.path
        del item.path  # save some space

        def file_version(item, path):
Severity: Minor
Found in src/borg/fuse.py - About 3 hrs 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

File archive_test.py has 291 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import json
import os
from collections import OrderedDict
from datetime import datetime, timezone
from io import StringIO
Severity: Minor
Found in src/borg/testsuite/archive_test.py - About 3 hrs to fix

    Function rows_to_table has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

        def rows_to_table(self, rows, write):
            def write_row_separator():
                write("+")
                for column_width in column_widths:
                    write("-" * (column_width + 1))
    Severity: Minor
    Found in scripts/make.py - About 2 hrs 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 generate_level has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

        def generate_level(self, prefix, parser, Archiver, extra_choices=None):
            is_subcommand = False
            choices = {}
            for action in parser._actions:
                if action.choices is not None and "SubParsersAction" in str(action.__class__):
    Severity: Minor
    Found in scripts/make.py - About 2 hrs 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 _update_index has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

        def _update_index(self, segment, objects, report=None):
            """some code shared between replay_segments and check"""
            self.segments[segment] = 0
            for tag, key, offset, size, _ in objects:
                if tag in (TAG_PUT2, TAG_PUT):
    Severity: Minor
    Found in src/borg/legacyrepository.py - About 2 hrs 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 with_repository has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

    def with_repository(
        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, …)
    Severity: Minor
    Found in src/borg/archiver/_common.py - About 2 hrs 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_diff has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

        def do_diff(self, args, repository, manifest):
            """Diff contents of two archives"""
    
            def actual_change(j):
                j = j.to_dict()
    Severity: Minor
    Found in src/borg/archiver/diff_cmd.py - About 2 hrs 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_chunkpoints_unchanged has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

    def test_chunkpoints_unchanged():
        def twist(size):
            x = 1
            a = bytearray(size)
            for i in range(size):
    Severity: Minor
    Found in src/borg/testsuite/chunker_slow_test.py - About 2 hrs 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 kill_stale_lock has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

        def kill_stale_lock(self):
            try:
                names = os.listdir(self.path)
            except FileNotFoundError:  # another process did our job in the meantime.
                return False
    Severity: Minor
    Found in src/borg/fslocking.py - About 2 hrs 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

    File benchmark_cmd.py has 284 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import argparse
    from contextlib import contextmanager
    import functools
    import os
    import tempfile
    Severity: Minor
    Found in src/borg/archiver/benchmark_cmd.py - About 2 hrs to fix

      Function __init__ has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

          def __init__(
              self,
              location,
              create=False,
              exclusive=False,
      Severity: Minor
      Found in src/borg/remote.py - About 2 hrs 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 get_by_id has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_by_id(self, id, raw=False):
              assert isinstance(id, bytes)
              if not self.legacy:
                  if id in self.ids():  # check directory
                      # looks like this archive id is in the archives directory, thus it is NOT deleted.
      Severity: Minor
      Found in src/borg/manifest.py - About 2 hrs 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 ChunkerParams has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

      def ChunkerParams(s):
          params = s.strip().split(",")
          count = len(params)
          if count == 0:
              raise argparse.ArgumentTypeError("no chunker params given")
      Severity: Minor
      Found in src/borg/helpers/parseformat.py - About 2 hrs 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 a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

          def __init__(
              self,
              location,
              create=False,
              exclusive=False,
      Severity: Minor
      Found in src/borg/legacyremote.py - About 2 hrs 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_fuse has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

      def test_fuse(archivers, request):
          archiver = request.getfixturevalue(archivers)
          if archiver.EXE and fakeroot_detected():
              pytest.skip("test_fuse with the binary is not compatible with fakeroot")
      
      
      Severity: Minor
      Found in src/borg/testsuite/archiver/mount_cmds_test.py - About 2 hrs 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

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

          with open(key_file, "w") as fd:
              fd.write(AESOCBKeyfileKey.FILE_ID + " " + repo_id + "\n")
              fd.write(binascii.b2a_base64(b"abcdefghijklmnopqrstu").decode())
      Severity: Major
      Found in src/borg/testsuite/archiver/key_cmds_test.py and 1 other location - About 2 hrs to fix
      src/borg/testsuite/archiver/key_cmds_test.py on lines 234..236

      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 59.

      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 2 locations. Consider refactoring.
      Open

          with open(key_file, "w") as fd:
              fd.write(CHPOKeyfileKey.FILE_ID + " " + repo_id + "\n")
              fd.write(binascii.b2a_base64(b"abcdefghijklmnopqrstu").decode())
      Severity: Major
      Found in src/borg/testsuite/archiver/key_cmds_test.py and 1 other location - About 2 hrs to fix
      src/borg/testsuite/archiver/key_cmds_test.py on lines 262..264

      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 59.

      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

      File patterns.py has 279 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      import argparse
      import fnmatch
      import os.path
      import re
      import sys
      Severity: Minor
      Found in src/borg/patterns.py - About 2 hrs to fix

        LoggedIO has 24 functions (exceeds 20 allowed). Consider refactoring.
        Open

        class LoggedIO:
            class SegmentFull(Exception):
                """raised when a segment is full, before opening next"""
        
            header_fmt = struct.Struct("<IIB")
        Severity: Minor
        Found in src/borg/legacyrepository.py - About 2 hrs to fix
          Severity
          Category
          Status
          Source
          Language