From b7b428edc2d019459c9d3c678b5ef13111ee28ae Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Sat, 22 Jul 2017 01:51:19 +0200 Subject: [PATCH 1/4] repository: fix assert expression to not have a side effect lgtm: This 'assert' statement contains an expression which may have side effects. --- src/borg/repository.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/borg/repository.py b/src/borg/repository.py index 5a3aa735c..b443bdb4e 100644 --- a/src/borg/repository.py +++ b/src/borg/repository.py @@ -642,7 +642,8 @@ class Repository: # get rid of the old, sparse, unused segments. free space. for segment in unused: logger.debug('complete_xfer: deleting unused segment %d', segment) - assert self.segments.pop(segment) == 0, 'Corrupted segment reference count - corrupted index or hints' + count = self.segments.pop(segment) + assert count == 0, 'Corrupted segment reference count - corrupted index or hints' self.io.delete_segment(segment) del self.compact[segment] unused = [] From 73e5ac4a2b706671551d62d143d81c07e7a3f033 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Sat, 22 Jul 2017 02:03:42 +0200 Subject: [PATCH 2/4] setup.py: fix same loop variables lgtm: Nested loops in which the target variable is the same for each loop make the behavior of the loops difficult to understand. (not really here, just wanted to get rid of lgtm warning) --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index b6aadf288..dd85db6a1 100644 --- a/setup.py +++ b/setup.py @@ -368,12 +368,12 @@ class build_usage(Command): # "+ 1" because we want a space between the cell contents and the delimiting "|" in the output column_widths[i] = max(column_widths[i], len(cells[i]) + 1) - for columns, *cells in rows: + for columns, *original_cells in rows: write_row_separator() # If a cell contains newlines, then the row must be split up in individual rows # where each cell contains no newline. rowspanning_cells = [] - original_cells = list(cells) + original_cells = list(original_cells) while any('\n' in cell for cell in original_cells): cell_bloc = [] for i, cell in enumerate(original_cells): From 5cc2b900eef4c55c14f3cc867fbc888b857b9a8c Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Sat, 22 Jul 2017 02:07:17 +0200 Subject: [PATCH 3/4] constants: avoid comparing constants lgtm: Comparison of constants is always constant, but is harder to read than a simple constant. --- src/borg/constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/borg/constants.py b/src/borg/constants.py index bcdaa07da..6c13a9c98 100644 --- a/src/borg/constants.py +++ b/src/borg/constants.py @@ -34,7 +34,7 @@ MAX_DATA_SIZE = 20971479 # MAX_OBJECT_SIZE = <20 MiB (MAX_DATA_SIZE) + 41 bytes for a Repository PUT header, which consists of # a 1 byte tag ID, 4 byte CRC, 4 byte size and 32 bytes for the ID. MAX_OBJECT_SIZE = MAX_DATA_SIZE + 41 # see LoggedIO.put_header_fmt.size assertion in repository module -assert MAX_OBJECT_SIZE == 20971520 == 20 * 1024 * 1024 +assert MAX_OBJECT_SIZE == 20 * 1024 * 1024 # borg.remote read() buffer size BUFSIZE = 10 * 1024 * 1024 From 199f192a65c8b753f5c09cd8c35abcd71131f7a6 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Sat, 22 Jul 2017 02:42:12 +0200 Subject: [PATCH 4/4] archive: closely wrap next() called from generator lgtm: Calling next() in a generator may cause unintended early termination of an iteration. It seems that lgtm did not detect the more loose wrapping that we used before. --- src/borg/archive.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/borg/archive.py b/src/borg/archive.py index aff947bb4..a32d10e51 100644 --- a/src/borg/archive.py +++ b/src/borg/archive.py @@ -172,11 +172,11 @@ backup_io = BackupIO() def backup_io_iter(iterator): backup_io.op = 'read' while True: - try: - with backup_io: + with backup_io: + try: item = next(iterator) - except StopIteration: - return + except StopIteration: + return yield item