mirror of
https://github.com/luanti-org/luanti.git
synced 2025-10-13 08:35:20 +02:00
Fix core.download_file() creating empty files on HTTP error
This commit is contained in:
@@ -530,7 +530,6 @@ bool GUIEngine::downloadFile(const std::string &url, const std::string &target)
|
|||||||
{
|
{
|
||||||
#if USE_CURL
|
#if USE_CURL
|
||||||
std::ofstream target_file(target.c_str(), std::ios::out | std::ios::binary);
|
std::ofstream target_file(target.c_str(), std::ios::out | std::ios::binary);
|
||||||
|
|
||||||
if (!target_file.good()) {
|
if (!target_file.good()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -543,6 +542,8 @@ bool GUIEngine::downloadFile(const std::string &url, const std::string &target)
|
|||||||
httpfetch_sync(fetch_request, fetch_result);
|
httpfetch_sync(fetch_request, fetch_result);
|
||||||
|
|
||||||
if (!fetch_result.succeeded) {
|
if (!fetch_result.succeeded) {
|
||||||
|
target_file.close();
|
||||||
|
fs::DeleteSingleFileOrEmptyDirectory(target);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
target_file << fetch_result.data;
|
target_file << fetch_result.data;
|
||||||
|
Reference in New Issue
Block a user