fix: calculate_md5 will return "" for nonexistent files

This commit is contained in:
tretrauit 2022-06-26 01:56:14 +07:00
parent 23980276ee
commit aa147792e6
Signed by: tretrauit
GPG Key ID: CDDE1C97EE305DAF
1 changed files with 4 additions and 1 deletions

View File

@ -492,7 +492,10 @@ class Installer:
contents = await pkg_version.read_text()
async def calculate_md5(file_to_calculate):
async with AsyncPath(file_to_calculate).open("rb") as f:
file_to_calculate = AsyncPath(file_to_calculate)
if not await file_to_calculate.exists():
return ""
async with file_to_calculate.open("rb") as f:
file_hash = hashlib.md5()
while chunk := await f.read(self._download_chunk):
file_hash.update(chunk)