mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-06 05:40:54 -06:00
file(DOWNLOAD): Handle write errors
This commit is contained in:
@@ -1703,7 +1703,9 @@ size_t cmWriteToFileCallback(void* ptr, size_t size, size_t nmemb, void* data)
|
||||
cmsys::ofstream* fout = static_cast<cmsys::ofstream*>(data);
|
||||
if (fout) {
|
||||
char const* chPtr = static_cast<char*>(ptr);
|
||||
fout->write(chPtr, realsize);
|
||||
if (!fout->write(chPtr, realsize)) {
|
||||
return CURL_WRITEFUNC_ERROR;
|
||||
}
|
||||
}
|
||||
return realsize;
|
||||
}
|
||||
@@ -2283,6 +2285,14 @@ bool HandleDownloadCommand(std::vector<std::string> const& args,
|
||||
g_curl.release();
|
||||
::curl_easy_cleanup(curl);
|
||||
|
||||
// Explicitly close the file so we can check for write errors.
|
||||
if (!file.empty()) {
|
||||
fout.close();
|
||||
if (!fout) {
|
||||
res = CURLE_WRITE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
if (!statusVar.empty()) {
|
||||
std::string m = curl_easy_strerror(res);
|
||||
if ((res == CURLE_SSL_CONNECT_ERROR ||
|
||||
@@ -2306,13 +2316,6 @@ bool HandleDownloadCommand(std::vector<std::string> const& args,
|
||||
status.GetMakefile().AddDefinition(logVar, chunkDebug.data());
|
||||
}
|
||||
|
||||
// Explicitly flush/close so we can measure the md5 accurately.
|
||||
//
|
||||
if (!file.empty()) {
|
||||
fout.flush();
|
||||
fout.close();
|
||||
}
|
||||
|
||||
// Verify MD5 sum if requested:
|
||||
//
|
||||
if (hash) {
|
||||
|
||||
Reference in New Issue
Block a user