Skip to content

Commit

Permalink
Use hashing from antsibull-fileutils.
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfontein committed Sep 8, 2024
1 parent 45274d3 commit 75b7195
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/antsibull/from_source/verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
from typing import TYPE_CHECKING, Any, TypedDict

import aiofiles.ospath
from antsibull_core.utils.hashing import verify_hash
from antsibull_core import app_context
from antsibull_fileutils.hashing import verify_hash

from antsibull.types import add_yaml_type

Expand Down Expand Up @@ -81,6 +82,7 @@ async def verify_files(
Yields:
`FileErrorOutput` dicts with error data
"""
lib_ctx = app_context.lib_ctx.get()
for file in files_data:
path = collection_dir / file["name"]
is_dir = file["ftype"] == "dir"
Expand All @@ -90,7 +92,10 @@ async def verify_files(
elif is_dir and not await aiofiles.ospath.isdir(path):
error = FileError.NOT_A_DIRECTORY
elif not is_dir and not await verify_hash(
path, file["chksum_sha256"], "sha256"
path,
file["chksum_sha256"],
algorithm="sha256",
chunksize=lib_ctx.chunksize,
):
error = FileError.WRONG_HASH
if error is not None and error not in (ignore_errors or set()):
Expand Down
6 changes: 4 additions & 2 deletions src/antsibull/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

import aiohttp
import pydantic as p
from antsibull_core.utils.hashing import verify_hash
from antsibull_core import app_context
from antsibull_fileutils.hashing import verify_hash

PYPI_BASE_URL = "https://pypi.org/pypi/"

Expand Down Expand Up @@ -108,7 +109,8 @@ async def verify_local_file(self, file: Path) -> bool:
"""
if file.name != self.filename:
return False
return await verify_hash(file, self.sha256sum)
lib_ctx = app_context.lib_ctx.get()
return await verify_hash(file, self.sha256sum, chunksize=lib_ctx.chunksize)


# TODO pydantic v2+:
Expand Down

0 comments on commit 75b7195

Please sign in to comment.