mirror of
https://github.com/borgbackup/borg.git
synced 2025-02-01 12:09:10 +00:00
seen_chunk: do not use .refcount
If we have an entry for a chunk id in the ChunkIndex, it means that this chunk exists in the repository. The code was a bit over-complicated and used entry.refcount only to detect whether .get(id, default) actually got something from the ChunkIndex or used the provided default value. The code does the same now, but in a simpler way. Additionally, it checks for size consistency if a size is provided by the caller and a size is already present in the entry.
This commit is contained in:
parent
5da1ff166f
commit
de1b7e0581
1 changed files with 8 additions and 5 deletions
|
@ -719,14 +719,17 @@ def chunks(self):
|
||||||
return self._chunks
|
return self._chunks
|
||||||
|
|
||||||
def seen_chunk(self, id, size=None):
|
def seen_chunk(self, id, size=None):
|
||||||
entry = self.chunks.get(id, ChunkIndexEntry(0, None))
|
entry = self.chunks.get(id)
|
||||||
if entry.refcount and size is not None:
|
entry_exists = entry is not None
|
||||||
assert isinstance(entry.size, int)
|
if entry_exists and size is not None:
|
||||||
if not entry.size:
|
if entry.size == 0:
|
||||||
# AdHocWithFilesCache:
|
# AdHocWithFilesCache:
|
||||||
# Here *size* is used to update the chunk's size information, which will be zero for existing chunks.
|
# Here *size* is used to update the chunk's size information, which will be zero for existing chunks.
|
||||||
self.chunks[id] = entry._replace(size=size)
|
self.chunks[id] = entry._replace(size=size)
|
||||||
return entry.refcount != 0
|
else:
|
||||||
|
# in case we already have a size information in the entry, check consistency:
|
||||||
|
assert size == entry.size
|
||||||
|
return entry_exists
|
||||||
|
|
||||||
def reuse_chunk(self, id, size, stats):
|
def reuse_chunk(self, id, size, stats):
|
||||||
assert isinstance(size, int) and size > 0
|
assert isinstance(size, int) and size > 0
|
||||||
|
|
Loading…
Reference in a new issue