MCPcopy
hub / github.com/borgbackup/borg / flush

Method flush

src/borg/archive.py:375–400  ·  view source on GitHub ↗
(self, flush=False)

Source from the content-addressed store, hash-verified

373 raise NotImplementedError
374
375 def flush(self, flush=False):
376 if self.buffer.tell() == 0:
377 return
378 self.buffer.seek(0)
379 # The chunker returns a memoryview to its internal buffer,
380 # thus a copy is needed before resuming the chunker iterator.
381 # the metadata stream may produce all-zero chunks, so deal
382 # with CH_ALLOC (and CH_HOLE, for completeness) here.
383 chunks = []
384 for chunk in self.chunker.chunkify(self.buffer):
385 alloc = chunk.meta["allocation"]
386 if alloc == CH_DATA:
387 data = bytes(chunk.data)
388 elif alloc in (CH_ALLOC, CH_HOLE):
389 data = zeros[: chunk.meta["size"]]
390 else:
391 raise ValueError("chunk allocation has unsupported value of %r" % alloc)
392 chunks.append(data)
393 self.buffer.seek(0)
394 self.buffer.truncate(0)
395 # Leave the last partial chunk in the buffer unless flush is True
396 end = None if flush or len(chunks) == 1 else -1
397 for chunk in chunks[:end]:
398 self.chunks.append(self.write_chunk(chunk))
399 if end == -1:
400 self.buffer.write(chunks[-1])
401
402 def is_full(self):
403 return self.buffer.tell() > self.BUFFER_SIZE

Callers 7

addMethod · 0.95
rebuild_archivesMethod · 0.95
flush_and_syncMethod · 0.45
remove_handlersFunction · 0.45
flush_loggingFunction · 0.45
saveMethod · 0.45
extract_itemMethod · 0.45

Calls 6

write_chunkMethod · 0.95
truncateMethod · 0.80
tellMethod · 0.45
seekMethod · 0.45
chunkifyMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected