objects: hash_file: retrieve size from hash_info (#6284)

* objects: hash_file: retrieve size from hash_info

* objects: drop Tree.size implementation
This commit is contained in:
Batuhan Taskaya
2021-07-06 10:56:13 +03:00
committed by GitHub
parent 9cf22d3edc
commit 98f7d1e481
3 changed files with 22 additions and 19 deletions
+1 -3
View File
@@ -28,9 +28,7 @@ class HashFile:
@property
def size(self):
if not (self.path_info and self.fs):
return None
return self.fs.getsize(self.path_info)
return self.hash_info.size
def __len__(self):
return 1
+4 -8
View File
@@ -28,13 +28,6 @@ class Tree(HashFile):
return Trie(self._dict)
@property
def size(self):
try:
return sum(obj.size for _, obj in self)
except TypeError:
return None
def add(self, key, obj):
self.__dict__.pop("trie", None)
self._dict[key] = obj
@@ -52,7 +45,10 @@ class Tree(HashFile):
self.path_info = path_info
self.hash_info = get_file_hash(path_info, memfs, "md5")
self.hash_info.value += ".dir"
self.hash_info.size = self.size
try:
self.hash_info.size = sum(obj.size for _, obj in self)
except TypeError:
self.hash_info.size = None
self.hash_info.nfiles = len(self)
def __len__(self):
+17 -8
View File
@@ -69,19 +69,27 @@ def test_list(lst, trie_dict):
({}, 0),
(
{
("a",): HashInfo("md5", "abc", size=1),
("b",): HashInfo("md5", "def", size=2),
("c",): HashInfo("md5", "ghi", size=3),
("dir", "foo"): HashInfo("md5", "jkl", size=4),
("dir", "bar"): HashInfo("md5", "mno", size=5),
("dir", "baz"): HashInfo("md5", "pqr", size=6),
("a",): HashFile(None, None, HashInfo("md5", "abc", size=1)),
("b",): HashFile(None, None, HashInfo("md5", "def", size=2)),
("c",): HashFile(None, None, HashInfo("md5", "ghi", size=3)),
("dir", "foo"): HashFile(
None, None, HashInfo("md5", "jkl", size=4)
),
("dir", "bar"): HashFile(
None, None, HashInfo("md5", "mno", size=5)
),
("dir", "baz"): HashFile(
None, None, HashInfo("md5", "pqr", size=6)
),
},
21,
),
(
{
("a",): HashInfo("md5", "abc", size=1),
("b",): HashInfo("md5", "def", size=None),
("a",): HashFile(None, None, HashInfo("md5", "abc", size=1)),
("b",): HashFile(
None, None, HashInfo("md5", "def", size=None)
),
},
None,
),
@@ -90,6 +98,7 @@ def test_list(lst, trie_dict):
def test_size(trie_dict, size):
tree = Tree(None, None, None)
tree._dict = trie_dict
tree.digest()
assert tree.size == size