mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-11 16:32:14 -06:00
file(DOWNLOAD): Fill STATUS variable on hash mismatch (#15987)
Although we fail with an error on a hash mismatch, it is not a fatal error so the script may continue processing. If the download itself had no error then report in the STATUS variable that the operation was not successful due to the hash mismatch. Suggested-by: Tobias Hieta <tobias@hieta.se>
This commit is contained in:
@@ -3300,6 +3300,15 @@ cmFileCommand::HandleDownloadCommand(std::vector<std::string> const& args)
|
||||
<< " status: [" << (int)res << ";\""
|
||||
<< ::curl_easy_strerror(res) << "\"]" << std::endl
|
||||
;
|
||||
|
||||
if(!statusVar.empty() && res == 0)
|
||||
{
|
||||
std::string status = "1;HASH mismatch: "
|
||||
"expected: " + expectedHash +
|
||||
" actual: " + actualHash;
|
||||
this->Makefile->AddDefinition(statusVar, status.c_str());
|
||||
}
|
||||
|
||||
this->SetError(oss.str());
|
||||
return false;
|
||||
}
|
||||
|
||||
1
Tests/RunCMake/file/DOWNLOAD-hash-mismatch-result.txt
Normal file
1
Tests/RunCMake/file/DOWNLOAD-hash-mismatch-result.txt
Normal file
@@ -0,0 +1 @@
|
||||
1
|
||||
12
Tests/RunCMake/file/DOWNLOAD-hash-mismatch-stderr.txt
Normal file
12
Tests/RunCMake/file/DOWNLOAD-hash-mismatch-stderr.txt
Normal file
@@ -0,0 +1,12 @@
|
||||
^CMake Error at DOWNLOAD-hash-mismatch.cmake:[0-9]+ \(file\):
|
||||
file DOWNLOAD HASH mismatch
|
||||
|
||||
for file: \[.*/Tests/RunCMake/file/DOWNLOAD-hash-mismatch-build/hash-mismatch.txt\]
|
||||
expected hash: \[0123456789abcdef0123456789abcdef01234567\]
|
||||
actual hash: \[da39a3ee5e6b4b0d3255bfef95601890afd80709\]
|
||||
status: \[0;"No error"\]
|
||||
|
||||
Call Stack \(most recent call first\):
|
||||
CMakeLists.txt:[0-9]+ \(include\)
|
||||
+
|
||||
status='1;HASH mismatch: expected: 0123456789abcdef0123456789abcdef01234567 actual: da39a3ee5e6b4b0d3255bfef95601890afd80709'$
|
||||
7
Tests/RunCMake/file/DOWNLOAD-hash-mismatch.cmake
Normal file
7
Tests/RunCMake/file/DOWNLOAD-hash-mismatch.cmake
Normal file
@@ -0,0 +1,7 @@
|
||||
file(DOWNLOAD
|
||||
"file://${CMAKE_CURRENT_SOURCE_DIR}/DOWNLOAD-hash-mismatch.txt"
|
||||
${CMAKE_CURRENT_BINARY_DIR}/hash-mismatch.txt
|
||||
EXPECTED_HASH SHA1=0123456789abcdef0123456789abcdef01234567
|
||||
STATUS status
|
||||
)
|
||||
message("status='${status}'")
|
||||
0
Tests/RunCMake/file/DOWNLOAD-hash-mismatch.txt
Normal file
0
Tests/RunCMake/file/DOWNLOAD-hash-mismatch.txt
Normal file
@@ -1,5 +1,6 @@
|
||||
include(RunCMake)
|
||||
|
||||
run_cmake(DOWNLOAD-hash-mismatch)
|
||||
run_cmake(INSTALL-DIRECTORY)
|
||||
run_cmake(INSTALL-MESSAGE-bad)
|
||||
run_cmake(FileOpenFailRead)
|
||||
|
||||
Reference in New Issue
Block a user