Skip to content

Commit

Permalink
[vcpkg_from_sourceforge] Skip mirrors that are in 'disaster recovery'…
Browse files Browse the repository at this point in the history
… mode (#13176)
  • Loading branch information
JackBoosY committed Aug 28, 2020
1 parent bf1d20c commit 6800300
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
3 changes: 0 additions & 3 deletions scripts/cmake/vcpkg_download_distfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ function(vcpkg_download_distfile VAR)
message(FATAL_ERROR "vcpkg_download_distfile requires a FILENAME argument.")
endif()
if(NOT _VCPKG_INTERNAL_NO_HASH_CHECK)
if(vcpkg_download_distfile_SKIP_SHA512 AND NOT VCPKG_USE_HEAD_VERSION)
message(FATAL_ERROR "vcpkg_download_distfile only allows SKIP_SHA512 when building with --head")
endif()
if(NOT vcpkg_download_distfile_SKIP_SHA512 AND NOT DEFINED vcpkg_download_distfile_SHA512)
message(FATAL_ERROR "vcpkg_download_distfile requires a SHA512 argument. If you do not know the SHA512, add it as 'SHA512 0' and re-run this command.")
endif()
Expand Down
46 changes: 41 additions & 5 deletions scripts/cmake/vcpkg_from_sourceforge.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,34 @@
## * [tinyfiledialogs](https://github.com/Microsoft/vcpkg/blob/master/ports/tinyfiledialogs/portfile.cmake)

function(vcpkg_from_sourceforge)
macro(check_file_content)
if (EXISTS ${ARCHIVE})
file(SIZE ${ARCHIVE} DOWNLOAD_FILE_SIZE)
if (DOWNLOAD_FILE_SIZE LESS_EQUAL 1024)
file(READ ${ARCHIVE} _FILE_CONTENT_)
string(FIND "${_FILE_CONTENT_}" "the Sourceforge site is currently in Disaster Recovery mode." OUT_CONTENT)
message("OUT_CONTENT: ${OUT_CONTENT}")
if (OUT_CONTENT EQUAL -1)
set(download_success 1)
else()
file(REMOVE ${ARCHIVE})
endif()
endif()
endif()
endmacro()

macro(check_file_sha512)
file(SHA512 ${ARCHIVE} FILE_HASH)
if(NOT FILE_HASH STREQUAL _vdus_SHA512)
message(FATAL_ERROR
"\nFile does not have expected hash:\n"
" File path: [ ${ARCHIVE} ]\n"
" Expected hash: [ ${_vdus_SHA512} ]\n"
" Actual hash: [ ${FILE_HASH} ]\n"
"${CUSTOM_ERROR_ADVICE}\n")
endif()
endmacro()

set(booleanValueArgs DISABLE_SSL NO_REMOVE_ONE_LEVEL)
set(oneValueArgs OUT_SOURCE_PATH REPO REF SHA512 FILENAME WORKING_DIRECTORY)
set(multipleValuesArgs PATCHES)
Expand Down Expand Up @@ -151,13 +179,15 @@ function(vcpkg_from_sourceforge)
message(STATUS "Trying auto-select mirror...")
vcpkg_download_distfile(ARCHIVE
URLS "${DOWNLOAD_URL}"
SHA512 "${_vdus_SHA512}"
SKIP_SHA512
FILENAME "${_vdus_FILENAME}"
SILENT_EXIT
)

if (EXISTS ${ARCHIVE})
set(download_success 1)
check_file_content()
if (download_success)
check_file_sha512()
else()
message(STATUS "The default mirror is in Disaster Recovery mode, trying other mirrors...")
endif()

if (NOT download_success EQUAL 1)
Expand All @@ -166,13 +196,19 @@ function(vcpkg_from_sourceforge)
message(STATUS "Trying mirror ${SOURCEFORGE_MIRROR}...")
vcpkg_download_distfile(ARCHIVE
URLS "${DOWNLOAD_URL}"
SHA512 "${_vdus_SHA512}"
SKIP_SHA512
FILENAME "${_vdus_FILENAME}"
SILENT_EXIT
)

if (EXISTS ${ARCHIVE})
set(download_success 1)
check_file_content()
if (download_success)
check_file_sha512()
else()
message(STATUS "Mirror ${SOURCEFORGE_MIRROR} is in Disaster Recovery mode, trying other mirrors...")
endif()
break()
endif()
endforeach()
Expand Down

0 comments on commit 6800300

Please sign in to comment.