diff --git a/src/borg/item.py b/src/borg/item.py index b97b470f2..0bc336239 100644 --- a/src/borg/item.py +++ b/src/borg/item.py @@ -160,10 +160,7 @@ class Item(PropDict): def file_size(self): if 'chunks' not in self: return 0 - total_size = 0 - for chunk_id, size, csize in self.chunks: - total_size += size - return total_size + return sum(chunk.size for chunk in self.chunks) class EncryptedKey(PropDict): diff --git a/src/borg/testsuite/item.py b/src/borg/testsuite/item.py index b0b7569e3..fc60e91df 100644 --- a/src/borg/testsuite/item.py +++ b/src/borg/testsuite/item.py @@ -1,5 +1,6 @@ import pytest +from ..cache import ChunkListEntry from ..item import Item from ..helpers import StableDict @@ -145,3 +146,16 @@ def test_unknown_property(): item = Item() with pytest.raises(AttributeError): item.unknown_attribute = None + + +def test_item_file_size(): + item = Item(chunks=[ + ChunkListEntry(csize=1, size=1000, id=None), + ChunkListEntry(csize=1, size=2000, id=None), + ]) + assert item.file_size() == 3000 + + +def test_item_file_size_no_chunks(): + item = Item() + assert item.file_size() == 0