From 8ca772285346b0d8484af147968d5c3b5a8be71b Mon Sep 17 00:00:00 2001 From: Sude Date: Mon, 14 May 2018 12:22:05 +0300 Subject: [PATCH] Skip complete files instead of trying to resume --- src/downloader.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/downloader.cpp b/src/downloader.cpp index d5aff23..cdf4676 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -1034,6 +1034,36 @@ CURLcode Downloader::downloadFile(const std::string& url, const std::string& fil { if (bSameVersion) { + // Check if file is complete so we can skip it instead of resuming + if (!xml_data.empty()) + { + off_t filesize_xml; + off_t filesize_local = boost::filesystem::file_size(filepath); + + tinyxml2::XMLDocument remote_xml; + remote_xml.Parse(xml_data.c_str()); + tinyxml2::XMLElement *fileElem = remote_xml.FirstChildElement("file"); + if (fileElem) + { + std::string total_size = fileElem->Attribute("total_size"); + try + { + filesize_xml = std::stoull(total_size); + } + catch (std::invalid_argument& e) + { + filesize_xml = 0; + } + if (filesize_local == filesize_xml) + { + std::cout << "Skipping complete file: " + filepath << std::endl; + fclose(outfile); + res = CURLE_OK; + return res; + } + } + } + // File exists, resume if ((outfile = freopen(filepath.c_str(), "r+", outfile))!=NULL ) { @@ -2681,6 +2711,34 @@ void Downloader::processDownloadQueue(Config conf, const unsigned int& tid) if (bSameVersion) { bResume = true; + + // Check if file is complete so we can skip it instead of resuming + if (!xml.empty()) + { + off_t filesize_xml; + off_t filesize_local = boost::filesystem::file_size(filepath); + + tinyxml2::XMLDocument remote_xml; + remote_xml.Parse(xml.c_str()); + tinyxml2::XMLElement *fileElem = remote_xml.FirstChildElement("file"); + if (fileElem) + { + std::string total_size = fileElem->Attribute("total_size"); + try + { + filesize_xml = std::stoull(total_size); + } + catch (std::invalid_argument& e) + { + filesize_xml = 0; + } + if (filesize_local == filesize_xml) + { + msgQueue.push(Message("Skipping complete file: " + filepath.filename().string(), MSGTYPE_INFO, msg_prefix)); + continue; + } + } + } } else {