Skip to content

Commit 19a7c5b

Browse files
committed
tests: do not read whole file at once for digest. Iterate instead.
1 parent 7eab6e3 commit 19a7c5b

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

tests/helpers/ptrack_helpers.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,9 +1774,9 @@ def pgdata_content(self, pgdata, ignore_ptrack=True, exclude_dirs=None):
17741774
file_relpath = os.path.relpath(file_fullpath, pgdata)
17751775
directory_dict['files'][file_relpath] = {'is_datafile': False}
17761776
with open(file_fullpath, 'rb') as f:
1777-
content = f.read()
17781777
# truncate cfm's content's zero tail
17791778
if file_relpath.endswith('.cfm'):
1779+
content = f.read()
17801780
zero64 = b"\x00"*64
17811781
l = len(content)
17821782
while l > 64:
@@ -1785,9 +1785,14 @@ def pgdata_content(self, pgdata, ignore_ptrack=True, exclude_dirs=None):
17851785
break
17861786
l = s
17871787
content = content[:l]
1788-
directory_dict['files'][file_relpath]['md5'] = hashlib.md5(content).hexdigest()
1789-
# directory_dict['files'][file_relpath]['md5'] = hashlib.md5(
1790-
# f = open(file_fullpath, 'rb').read()).hexdigest()
1788+
digest = hashlib.md5(content)
1789+
else:
1790+
digest = hashlib.md5()
1791+
while True:
1792+
b = f.read(64*1024)
1793+
if not b: break
1794+
digest.update(b)
1795+
directory_dict['files'][file_relpath]['md5'] = digest.hexdigest()
17911796

17921797
# crappy algorithm
17931798
if file.isdigit():

0 commit comments

Comments
 (0)