mirror of
https://github.com/Sude-/lgogdownloader.git
synced 2024-11-20 11:49:17 +01:00
Retry failed/partially downloaded files
Added --retries option to set maximum number of retries
This commit is contained in:
parent
3f7669a775
commit
f671834068
@ -50,6 +50,7 @@ class Config
|
||||
std::string sOrphanRegex;
|
||||
unsigned int iInstallerType;
|
||||
unsigned int iInstallerLanguage;
|
||||
int iRetries;
|
||||
size_t iChunkSize;
|
||||
curl_off_t iDownloadRate;
|
||||
long int iTimeout;
|
||||
|
@ -78,6 +78,7 @@ class Downloader
|
||||
std::string coverXML;
|
||||
|
||||
size_t resume_position;
|
||||
int retries;
|
||||
std::ofstream report_ofs;
|
||||
};
|
||||
|
||||
|
1
main.cpp
1
main.cpp
@ -151,6 +151,7 @@ int main(int argc, char *argv[])
|
||||
("verbose", bpo::value<bool>(&config.bVerbose)->zero_tokens()->default_value(false), "Print lots of information")
|
||||
("insecure", bpo::value<bool>(&bInsecure)->zero_tokens()->default_value(false), "Don't verify authenticity of SSL certificates")
|
||||
("timeout", bpo::value<long int>(&config.iTimeout)->default_value(10), "Set timeout for connection\nMaximum time in seconds that connection phase is allowed to take")
|
||||
("retries", bpo::value<int>(&config.iRetries)->default_value(3), "Set maximum number of retries on failed download")
|
||||
;
|
||||
// Options read from config file
|
||||
options_cfg_only.add_options()
|
||||
|
@ -49,6 +49,7 @@ Downloader::~Downloader()
|
||||
int Downloader::init()
|
||||
{
|
||||
this->resume_position = 0;
|
||||
this->retries = 0;
|
||||
|
||||
// Initialize curl and set curl options
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
@ -765,7 +766,7 @@ CURLcode Downloader::downloadFile(const std::string& url, const std::string& fil
|
||||
fclose(outfile);
|
||||
|
||||
// Download failed and was not a resume attempt so delete the file
|
||||
if (res != CURLE_OK && !bResume)
|
||||
if ( (res != CURLE_OK || res != CURLE_PARTIAL_FILE) && !bResume )
|
||||
{
|
||||
boost::filesystem::path path = filepath;
|
||||
if (boost::filesystem::exists(path))
|
||||
@ -782,6 +783,17 @@ CURLcode Downloader::downloadFile(const std::string& url, const std::string& fil
|
||||
this->report_ofs << report_line << std::endl;
|
||||
}
|
||||
|
||||
// Retry partially downloaded file
|
||||
if (res == CURLE_PARTIAL_FILE && (this->retries < config.iRetries) )
|
||||
{
|
||||
this->retries++;
|
||||
res = this->downloadFile(url, filepath, xml_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->retries = 0; // Reset retries counter
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user