From 709235613f5f1f51afc36cfc671e0cc2cb3b96f8 Mon Sep 17 00:00:00 2001 From: Sude Date: Fri, 1 Sep 2017 08:08:33 +0300 Subject: [PATCH] Add retry limit for failed chunk repairs If repairing a chunk failed then the downloader could get stuck in infinite loop trying to repair the chunk. This fixes the issue by adding a retry limit for failed chunk repairs. --- src/downloader.cpp | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/downloader.cpp b/src/downloader.cpp index 4d2c7e3..ef04fc2 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -289,7 +289,6 @@ int Downloader::login() if (!boost::filesystem::remove(Globals::globalConfig.curlConf.sCookiePath)) std::cerr << "Failed to delete " << Globals::globalConfig.curlConf.sCookiePath << std::endl; - //if (!gogWebsite->Login(email, password)) if (!gogWebsite->Login(email, password)) { std::cerr << "HTTP: Login failed" << std::endl; @@ -1555,6 +1554,9 @@ int Downloader::repairFile(const std::string& url, const std::string& filepath, // Check all chunks int iChunksRepaired = 0; + int iChunkRetryCount = 0; + int iChunkRetryLimit = 3; + bool bChunkRetryLimitReached = false; for (int i=0; i= iChunkRetryLimit) + { + bChunkRetryLimitReached = true; + } } else { std::cout << "OK\r" << std::flush; + iChunkRetryCount = 0; // reset retry count } free(chunk); res = 1; @@ -1608,10 +1628,17 @@ int Downloader::repairFile(const std::string& url, const std::string& filepath, if (Globals::globalConfig.bReport) { - std::string report_line = "Repaired [" + std::to_string(iChunksRepaired) + "/" + std::to_string(chunks) + "] " + filepath; + std::string report_line; + if (bChunkRetryLimitReached) + report_line = "Repair failed: " + filepath; + else + report_line = "Repaired [" + std::to_string(iChunksRepaired) + "/" + std::to_string(chunks) + "] " + filepath; this->report_ofs << report_line << std::endl; } + if (bChunkRetryLimitReached) + return res; + // Set timestamp for downloaded file to same value as file on server long filetime = -1; CURLcode result = curl_easy_getinfo(curlhandle, CURLINFO_FILETIME, &filetime);