aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorNinetainedo <ninetainedo@gmail.com>2016-09-25 00:36:50 +0200
committerNinetainedo <ninetainedo@gmail.com>2016-09-25 00:36:50 +0200
commit586c96e1b13c1bd4f7b5db483568cc5743a7a519 (patch)
tree5fd24680ec2f52982a997720d646b50b9b5145fa /scripts
parentc55c9df2285f0c66f054cb4591248501ba3e70fd (diff)
downloadvcpkg-586c96e1b13c1bd4f7b5db483568cc5743a7a519.tar.gz
vcpkg-586c96e1b13c1bd4f7b5db483568cc5743a7a519.zip
Used a function to check file integrity
Diffstat (limited to 'scripts')
-rw-r--r--scripts/cmake/vcpkg_download_distfile.cmake26
1 files changed, 11 insertions, 15 deletions
diff --git a/scripts/cmake/vcpkg_download_distfile.cmake b/scripts/cmake/vcpkg_download_distfile.cmake
index a2f13cd42..44b562573 100644
--- a/scripts/cmake/vcpkg_download_distfile.cmake
+++ b/scripts/cmake/vcpkg_download_distfile.cmake
@@ -3,10 +3,10 @@ function(vcpkg_download_distfile VAR)
set(oneValueArgs FILENAME SHA512)
set(multipleValuesArgs URLS)
cmake_parse_arguments(vcpkg_download_distfile "" "${oneValueArgs}" "${multipleValuesArgs}" ${ARGN})
-
set(downloaded_file_path ${DOWNLOADS}/${vcpkg_download_distfile_FILENAME})
- if(EXISTS ${downloaded_file_path})
- message(STATUS "Using cached ${downloaded_file_path}")
+
+ function(test_hash FILE_KIND CUSTOM_ERROR_ADVICE)
+ message(STATUS "Testing integrity of ${FILE_KIND}...")
file(SHA512 ${downloaded_file_path} FILE_HASH)
if(NOT "${FILE_HASH}" STREQUAL "${vcpkg_download_distfile_SHA512}")
message(FATAL_ERROR
@@ -14,8 +14,14 @@ function(vcpkg_download_distfile VAR)
" File path: [ ${downloaded_file_path} ]\n"
" Expected hash: [ ${vcpkg_download_distfile_SHA512} ]\n"
" Actual hash: [ ${FILE_HASH} ]\n"
- "Please delete the file and try again if this file should be downloaded again.\n")
+ "${CUSTOM_ERROR_ADVICE}\n")
endif()
+ message(STATUS "Testing integrity of ${FILE_KIND}... OK")
+ endfunction()
+
+ if(EXISTS ${downloaded_file_path})
+ message(STATUS "Using cached ${downloaded_file_path}")
+ test_hash("cached file" "Please delete the file and retry if this file should be downloaded again.")
else()
# Tries to download the file.
foreach(url IN LISTS vcpkg_download_distfile_URLS)
@@ -39,17 +45,7 @@ function(vcpkg_download_distfile VAR)
" Failed to download file.\n"
" Add mirrors or submit an issue at https://github.com/Microsoft/vcpkg/issues\n")
else()
- message(STATUS "Testing integrity of downloaded file...")
- file(SHA512 ${downloaded_file_path} FILE_HASH)
- if(NOT "${FILE_HASH}" STREQUAL "${vcpkg_download_distfile_SHA512}")
- message(FATAL_ERROR
- "\nFile does not have expected hash:\n"
- " File path: [ ${downloaded_file_path} ]\n"
- " Expected hash: [ ${vcpkg_download_distfile_SHA512} ]\n"
- " Actual hash: [ ${FILE_HASH} ]\n"
- "The file may be corrupted.\n")
- endif()
- message(STATUS "Testing integrity of downloaded file... OK")
+ test_hash("downloaded file" "The file may be corrupted.")
endif()
endif()
set(${VAR} ${downloaded_file_path} PARENT_SCOPE)