From 4f5300be75d9ad9a7e1fe43eaab3f0066039f956 Mon Sep 17 00:00:00 2001 From: Sude Date: Mon, 30 May 2016 14:54:57 +0300 Subject: [PATCH] Delete file on failed download File is deleted if the download wasn't a resume attempt or the result is zero length file --- src/downloader.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/downloader.cpp b/src/downloader.cpp index 45f53a1..97f5625 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -3034,6 +3034,16 @@ void Downloader::processDownloadQueue(Config conf, const unsigned int& tid) else { msgQueue.push(msg_prefix + "Finished download (" + static_cast(curl_easy_strerror(result)) + "): " + filepath.filename().string()); + + // Delete the file if download failed and was not a resume attempt or the result is zero length file + if (boost::filesystem::exists(filepath) && boost::filesystem::is_regular_file(filepath)) + { + if ((result != CURLE_PARTIAL_FILE && !bResume && result != CURLE_OPERATION_TIMEDOUT) || boost::filesystem::file_size(filepath) == 0) + { + if (!boost::filesystem::remove(filepath)) + msgQueue.push(msg_prefix + "Failed to delete " + filepath.filename().string()); + } + } } // Automatic xml creation