From: rubenwardy Date: Sun, 3 Feb 2019 17:30:33 +0000 (+0000) Subject: Fix core.download_file() creating empty files on HTTP error X-Git-Tag: 5.0.0~50 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=9a071d66a59bd0db72d09a3ca75b2ab9247dda92;p=oweals%2Fminetest.git Fix core.download_file() creating empty files on HTTP error --- 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;