Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Galaxy downloader to trust collection cache #78

Merged
6 changes: 3 additions & 3 deletions src/antsibull_core/galaxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ async def download(
if self.collection_cache and self.trust_collection_cache:
cached_copy = os.path.join(self.collection_cache, filename)
if os.path.isfile(cached_copy):
await copy_file(cached_copy, download_filename)
await copy_file(cached_copy, download_filename, check_content=False)
return download_filename

release_info = await self.get_release_info(f"{namespace}/{name}", version)
Expand All @@ -447,7 +447,7 @@ async def download(
cached_copy = os.path.join(self.collection_cache, filename)
if os.path.isfile(cached_copy):
if await verify_hash(cached_copy, sha256sum):
await copy_file(cached_copy, download_filename)
await copy_file(cached_copy, download_filename, check_content=False)
return download_filename

async with retry_get(
Expand All @@ -471,7 +471,7 @@ async def download(
# Copy downloaded collection into cache
if self.collection_cache:
cached_copy = os.path.join(self.collection_cache, filename)
await copy_file(download_filename, cached_copy)
await copy_file(download_filename, cached_copy, check_content=False)

return download_filename

Expand Down
8 changes: 6 additions & 2 deletions src/antsibull_core/utils/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,22 @@
mlog = log.fields(mod=__name__)


async def copy_file(source_path: StrOrBytesPath, dest_path: StrOrBytesPath) -> None:
async def copy_file(source_path: StrOrBytesPath, dest_path: StrOrBytesPath,
check_content: bool = True) -> None:
"""
Copy content from one file to another.

:arg source_path: Source path. Must be a file.
:arg dest_path: Destination path.
:kwarg check_content: If ``True`` (default) and ``lib_ctx.file_check_content > 0`` and the
destination file exists, first check whether source and destination are potentially equal
before actually copying,
felixfontein marked this conversation as resolved.
Show resolved Hide resolved
"""
flog = mlog.fields(func="copy_file")
flog.debug("Enter")

lib_ctx = app_context.lib_ctx.get()
if lib_ctx.file_check_content > 0:
if check_content and lib_ctx.file_check_content > 0:
# Check whether the destination file exists and has the same content as the source file,
# in which case we won't overwrite the destination file
try:
Expand Down