aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubenwardy <rw@rubenwardy.com>2019-02-03 17:30:33 +0000
committerrubenwardy <rw@rubenwardy.com>2019-02-03 17:31:28 +0000
commit9a071d66a59bd0db72d09a3ca75b2ab9247dda92 (patch)
tree131f315eace9fffbc53678d92a6bc37427b8ea6b
parent809cb9fc0bcf89d247f509a42351db102a0e278c (diff)
downloadminetest-9a071d66a59bd0db72d09a3ca75b2ab9247dda92.tar.gz
minetest-9a071d66a59bd0db72d09a3ca75b2ab9247dda92.tar.bz2
minetest-9a071d66a59bd0db72d09a3ca75b2ab9247dda92.zip
Fix core.download_file() creating empty files on HTTP error
-rw-r--r--src/gui/guiEngine.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/gui/guiEngine.cpp b/src/gui/guiEngine.cpp
index a61847a04..92e9db0fc 100644
--- a/src/gui/guiEngine.cpp
+++ b/src/gui/guiEngine.cpp
@@ -530,7 +530,6 @@ bool GUIEngine::downloadFile(const std::string &url, const std::string &target)
{
#if USE_CURL
std::ofstream target_file(target.c_str(), std::ios::out | std::ios::binary);
-
if (!target_file.good()) {
return false;
}
@@ -543,6 +542,8 @@ bool GUIEngine::downloadFile(const std::string &url, const std::string &target)
httpfetch_sync(fetch_request, fetch_result);
if (!fetch_result.succeeded) {
+ target_file.close();
+ fs::DeleteSingleFileOrEmptyDirectory(target);
return false;
}
target_file << fetch_result.data;