mirror of
https://github.com/microsoft/vcpkg.git
synced 2025-06-07 11:22:48 +08:00
[vcpkg_download_distfile] Check SHA512 for already downloaded files (#20988)
* [vcpkg_download_distfile] Check SHA512 for already downloaded files * [vcpkg_download_distfile] Respect SKIP_SHA512 to enable --head
This commit is contained in:
parent
a875d75674
commit
75b6191dff
@ -58,7 +58,7 @@ The helper [`vcpkg_from_github`](vcpkg_from_github.md) should be used for downlo
|
|||||||
* [freetype](https://github.com/Microsoft/vcpkg/blob/master/ports/freetype/portfile.cmake)
|
* [freetype](https://github.com/Microsoft/vcpkg/blob/master/ports/freetype/portfile.cmake)
|
||||||
#]===]
|
#]===]
|
||||||
|
|
||||||
function(z_vcpkg_download_distfile_test_hash path kind error_advice sha512 skip_sha512)
|
function(z_vcpkg_download_distfile_test_hash file_path kind error_advice sha512 skip_sha512)
|
||||||
if(_VCPKG_INTERNAL_NO_HASH_CHECK)
|
if(_VCPKG_INTERNAL_NO_HASH_CHECK)
|
||||||
# When using the internal hash skip, do not output an explicit message.
|
# When using the internal hash skip, do not output an explicit message.
|
||||||
return()
|
return()
|
||||||
@ -68,14 +68,14 @@ function(z_vcpkg_download_distfile_test_hash path kind error_advice sha512 skip_
|
|||||||
return()
|
return()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
file(SHA512 "${path}" file_hash)
|
file(SHA512 "${file_path}" file_hash)
|
||||||
if(NOT "${file_hash}" STREQUAL "${sha512}")
|
if(NOT "${file_hash}" STREQUAL "${sha512}")
|
||||||
message(FATAL_ERROR
|
message(FATAL_ERROR
|
||||||
"\nFile does not have expected hash:\n"
|
"\nFile does not have expected hash:\n"
|
||||||
" File path: [ ${file_path} ]\n"
|
" File path: [ ${file_path} ]\n"
|
||||||
" Expected hash: [ ${sha512} ]\n"
|
" Expected hash: [ ${sha512} ]\n"
|
||||||
" Actual hash: [ ${file_hash} ]\n"
|
" Actual hash: [ ${file_hash} ]\n"
|
||||||
"${CUSTOM_ERROR_ADVICE}\n")
|
"${error_advice}\n")
|
||||||
endif()
|
endif()
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
@ -204,21 +204,38 @@ If you do not know the SHA512, add it as 'SHA512 0' and re-run this command.")
|
|||||||
file(REMOVE_RECURSE "${DOWNLOADS}/temp")
|
file(REMOVE_RECURSE "${DOWNLOADS}/temp")
|
||||||
file(MAKE_DIRECTORY "${DOWNLOADS}/temp")
|
file(MAKE_DIRECTORY "${DOWNLOADS}/temp")
|
||||||
|
|
||||||
|
# check if file with same name already exists in downloads
|
||||||
|
if(EXISTS "${downloaded_file_path}")
|
||||||
|
set(advice_message "The cached file SHA512 doesn't match. The file may have been corrupted.")
|
||||||
|
if(_VCPKG_NO_DOWNLOADS)
|
||||||
|
string(APPEND advice_message " Downloads are disabled please provide a valid file at path ${downloaded_file_path} and retry.")
|
||||||
|
else()
|
||||||
|
string(APPEND advice_message " To re-download this file please delete cached file at path ${downloaded_file_path} and retry.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
z_vcpkg_download_distfile_test_hash(
|
||||||
|
"${downloaded_file_path}"
|
||||||
|
"cached file"
|
||||||
|
"${advice_message}"
|
||||||
|
"${arg_SHA512}"
|
||||||
|
"${arg_SKIP_SHA512}"
|
||||||
|
)
|
||||||
|
|
||||||
|
if(NOT vcpkg_download_distfile_QUIET)
|
||||||
|
message(STATUS "Using cached ${arg_FILENAME}.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Suppress the "Downloading ${arg_URLS} -> ${arg_FILENAME}..." message
|
||||||
|
set(vcpkg_download_distfile_QUIET TRUE)
|
||||||
|
endif()
|
||||||
|
|
||||||
# vcpkg_download_distfile_ALWAYS_REDOWNLOAD only triggers when NOT _VCPKG_NO_DOWNLOADS
|
# vcpkg_download_distfile_ALWAYS_REDOWNLOAD only triggers when NOT _VCPKG_NO_DOWNLOADS
|
||||||
# this could be de-morgan'd out but it's more clear this way
|
# this could be de-morgan'd out but it's more clear this way
|
||||||
if(_VCPKG_NO_DOWNLOADS)
|
if(_VCPKG_NO_DOWNLOADS)
|
||||||
if(NOT EXISTS "${downloaded_file_path}")
|
if(NOT EXISTS "${downloaded_file_path}")
|
||||||
message(FATAL_ERROR "Downloads are disabled, but '${downloaded_file_path}' does not exist.")
|
message(FATAL_ERROR "Downloads are disabled, but '${downloaded_file_path}' does not exist.")
|
||||||
endif()
|
endif()
|
||||||
if(NOT arg_QUIET)
|
|
||||||
message(STATUS "Using ${downloaded_file_path}")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
z_vcpkg_download_distfile_test_hash(
|
|
||||||
"${downloaded_file_path}"
|
|
||||||
"cached file"
|
|
||||||
"Please delete the file and retry if this file should be downloaded again."
|
|
||||||
)
|
|
||||||
set("${out_var}" "${downloaded_file_path}" PARENT_SCOPE)
|
set("${out_var}" "${downloaded_file_path}" PARENT_SCOPE)
|
||||||
return()
|
return()
|
||||||
endif()
|
endif()
|
||||||
|
Loading…
Reference in New Issue
Block a user