Skip to content

Commit

Permalink
Merge pull request borgbackup#6592 from ThomasWaldmann/fix-md-chunks-…
Browse files Browse the repository at this point in the history
…processing-master

metadata stream can produce all-zero chunks, fixes borgbackup#6587
  • Loading branch information
ThomasWaldmann authored Apr 14, 2022
2 parents 1b9a49c + e199f5b commit 3ef355a
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/borg/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,10 +362,18 @@ def flush(self, flush=False):
self.buffer.seek(0)
# The chunker returns a memoryview to its internal buffer,
# thus a copy is needed before resuming the chunker iterator.
# note: this is the items metadata stream chunker, we only will get CH_DATA allocation here (because there are,
# no all-zero chunks in a metadata stream), thus chunk.data will always be bytes/memoryview and allocation
# is always CH_DATA and never CH_ALLOC/CH_HOLE).
chunks = list(bytes(chunk.data) for chunk in self.chunker.chunkify(self.buffer))
# the metadata stream may produce all-zero chunks, so deal
# with CH_ALLOC (and CH_HOLE, for completeness) here.
chunks = []
for chunk in self.chunker.chunkify(self.buffer):
alloc = chunk.meta['allocation']
if alloc == CH_DATA:
data = bytes(chunk.data)
elif alloc in (CH_ALLOC, CH_HOLE):
data = zeros[:chunk.meta['size']]
else:
raise ValueError("chunk allocation has unsupported value of %r" % alloc)
chunks.append(data)
self.buffer.seek(0)
self.buffer.truncate(0)
# Leave the last partial chunk in the buffer unless flush is True
Expand Down

0 comments on commit 3ef355a

Please sign in to comment.