From 7da0a9c98232850068e9dbc8114a4e7e48e8e7bc Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Mon, 20 Feb 2017 22:24:19 +0100 Subject: [PATCH] borg extract: check file size consistency --- src/borg/archive.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/borg/archive.py b/src/borg/archive.py index 852da6e02..91e94fa5d 100644 --- a/src/borg/archive.py +++ b/src/borg/archive.py @@ -467,13 +467,20 @@ Utilization of max. archive size: {csize_max:.0%} has_damaged_chunks = 'chunks_healthy' in item if dry_run or stdout: if 'chunks' in item: + item_chunks_size = 0 for _, data in self.pipeline.fetch_many([c.id for c in item.chunks], is_preloaded=True): if pi: pi.show(increase=len(data), info=[remove_surrogates(item.path)]) if stdout: sys.stdout.buffer.write(data) + item_chunks_size += len(data) if stdout: sys.stdout.buffer.flush() + if 'size' in item: + item_size = item.size + if item_size != item_chunks_size: + logger.warning('{}: size inconsistency detected: size {}, chunks size {}'.format( + item.path, item_size, item_chunks_size)) if has_damaged_chunks: logger.warning('File %s has damaged (all-zero) chunks. Try running borg check --repair.' % remove_surrogates(item.path)) @@ -530,10 +537,15 @@ Utilization of max. archive size: {csize_max:.0%} else: fd.write(data) with backup_io('truncate'): - pos = fd.tell() + pos = item_chunks_size = fd.tell() fd.truncate(pos) fd.flush() self.restore_attrs(path, item, fd=fd.fileno()) + if 'size' in item: + item_size = item.size + if item_size != item_chunks_size: + logger.warning('{}: size inconsistency detected: size {}, chunks size {}'.format( + item.path, item_size, item_chunks_size)) if has_damaged_chunks: logger.warning('File %s has damaged (all-zero) chunks. Try running borg check --repair.' % remove_surrogates(item.path))