[vcpkg_download_distfile] Now downloads in a temp dir and rename to the target location

This commit is contained in:
Alexander Karatarakis 2017-11-02 18:54:10 -07:00
parent 66ad158be4
commit 24c3f87bf4

View File

@ -38,7 +38,12 @@ 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})
set(download_file_path_part "${DOWNLOADS}/temp/${vcpkg_download_distfile_FILENAME}")
file(REMOVE_RECURSE "${DOWNLOADS}/temp")
file(MAKE_DIRECTORY "${DOWNLOADS}/temp")
function(test_hash FILE_KIND CUSTOM_ERROR_ADVICE)
message(STATUS "Testing integrity of ${FILE_KIND}...")
@ -65,13 +70,13 @@ function(vcpkg_download_distfile VAR)
# Tries to download the file.
foreach(url IN LISTS vcpkg_download_distfile_URLS)
message(STATUS "Downloading ${url}...")
file(DOWNLOAD ${url} ${downloaded_file_path} STATUS download_status)
file(DOWNLOAD ${url} "${download_file_path_part}" STATUS download_status SHOW_PROGRESS)
list(GET download_status 0 status_code)
if (NOT "${status_code}" STREQUAL "0")
message(STATUS "Downloading ${url}... Failed. Status: ${download_status}")
file(REMOVE ${downloaded_file_path})
set(download_success 0)
else()
file(RENAME ${download_file_path_part} ${downloaded_file_path})
message(STATUS "Downloading ${url}... OK")
set(download_success 1)
break()