mirror of
https://github.com/Sude-/lgogdownloader.git
synced 2025-02-02 05:52:31 +01:00
Make failure to set timestamp not critical
Print warning message about the error but continue instead of dying
This commit is contained in:
parent
04592d512a
commit
eef1d4d15e
@ -1152,8 +1152,15 @@ CURLcode Downloader::downloadFile(const std::string& url, const std::string& fil
|
|||||||
if (result == CURLE_OK && filetime >= 0)
|
if (result == CURLE_OK && filetime >= 0)
|
||||||
{
|
{
|
||||||
std::time_t timestamp = (std::time_t)filetime;
|
std::time_t timestamp = (std::time_t)filetime;
|
||||||
|
try
|
||||||
|
{
|
||||||
boost::filesystem::last_write_time(filepath, timestamp);
|
boost::filesystem::last_write_time(filepath, timestamp);
|
||||||
}
|
}
|
||||||
|
catch(const boost::filesystem::filesystem_error& e)
|
||||||
|
{
|
||||||
|
std::cerr << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
curl_easy_setopt(curlhandle, CURLOPT_FILETIME, 0L);
|
curl_easy_setopt(curlhandle, CURLOPT_FILETIME, 0L);
|
||||||
|
|
||||||
@ -1457,8 +1464,15 @@ int Downloader::repairFile(const std::string& url, const std::string& filepath,
|
|||||||
if (result == CURLE_OK && filetime >= 0)
|
if (result == CURLE_OK && filetime >= 0)
|
||||||
{
|
{
|
||||||
std::time_t timestamp = (std::time_t)filetime;
|
std::time_t timestamp = (std::time_t)filetime;
|
||||||
|
try
|
||||||
|
{
|
||||||
boost::filesystem::last_write_time(filepath, timestamp);
|
boost::filesystem::last_write_time(filepath, timestamp);
|
||||||
}
|
}
|
||||||
|
catch(const boost::filesystem::filesystem_error& e)
|
||||||
|
{
|
||||||
|
std::cerr << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
curl_easy_setopt(curlhandle, CURLOPT_FILETIME, 0L);
|
curl_easy_setopt(curlhandle, CURLOPT_FILETIME, 0L);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
@ -2832,8 +2846,15 @@ void Downloader::processDownloadQueue(Config conf, const unsigned int& tid)
|
|||||||
if (res == CURLE_OK && filetime >= 0)
|
if (res == CURLE_OK && filetime >= 0)
|
||||||
{
|
{
|
||||||
std::time_t timestamp = (std::time_t)filetime;
|
std::time_t timestamp = (std::time_t)filetime;
|
||||||
|
try
|
||||||
|
{
|
||||||
boost::filesystem::last_write_time(filepath, timestamp);
|
boost::filesystem::last_write_time(filepath, timestamp);
|
||||||
}
|
}
|
||||||
|
catch(const boost::filesystem::filesystem_error& e)
|
||||||
|
{
|
||||||
|
msgQueue.push(Message(e.what(), MSGTYPE_WARNING, msg_prefix));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Average download speed
|
// Average download speed
|
||||||
std::ostringstream dlrate_avg;
|
std::ostringstream dlrate_avg;
|
||||||
@ -3982,7 +4003,16 @@ void Downloader::processGalaxyDownloadQueue(const std::string& install_path, Con
|
|||||||
|
|
||||||
// Set timestamp for downloaded file to same value as file on server
|
// Set timestamp for downloaded file to same value as file on server
|
||||||
if (boost::filesystem::exists(path) && timestamp >= 0)
|
if (boost::filesystem::exists(path) && timestamp >= 0)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
boost::filesystem::last_write_time(path, timestamp);
|
boost::filesystem::last_write_time(path, timestamp);
|
||||||
|
}
|
||||||
|
catch(const boost::filesystem::filesystem_error& e)
|
||||||
|
{
|
||||||
|
msgQueue.push(Message(e.what(), MSGTYPE_WARNING, msg_prefix));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
msgQueue.push(Message("Download complete: " + path.string(), MSGTYPE_SUCCESS, msg_prefix));
|
msgQueue.push(Message("Download complete: " + path.string(), MSGTYPE_SUCCESS, msg_prefix));
|
||||||
}
|
}
|
||||||
@ -4857,8 +4887,17 @@ void Downloader::processGalaxyDownloadQueue_MojoSetupHack(Config conf, const uns
|
|||||||
|
|
||||||
// Set timestamp
|
// Set timestamp
|
||||||
if (zfe.timestamp > 0)
|
if (zfe.timestamp > 0)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
boost::filesystem::last_write_time(path, zfe.timestamp);
|
boost::filesystem::last_write_time(path, zfe.timestamp);
|
||||||
}
|
}
|
||||||
|
catch(const boost::filesystem::filesystem_error& e)
|
||||||
|
{
|
||||||
|
msgQueue.push(Message(e.what(), MSGTYPE_WARNING, msg_prefix));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else // Use temporary file for bigger files
|
else // Use temporary file for bigger files
|
||||||
{
|
{
|
||||||
@ -4926,9 +4965,12 @@ void Downloader::processGalaxyDownloadQueue_MojoSetupHack(Config conf, const uns
|
|||||||
{
|
{
|
||||||
// Extract file
|
// Extract file
|
||||||
int res = ZipUtil::extractFile(path_tmp.string(), path.string());
|
int res = ZipUtil::extractFile(path_tmp.string(), path.string());
|
||||||
|
bool bFailed = false;
|
||||||
if (res != 0)
|
if (res != 0)
|
||||||
{
|
{
|
||||||
|
bFailed = true;
|
||||||
std::string msg = "Extraction failed (";
|
std::string msg = "Extraction failed (";
|
||||||
|
unsigned int msg_type = MSGTYPE_ERROR;
|
||||||
switch (res)
|
switch (res)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
@ -4943,17 +4985,23 @@ void Downloader::processGalaxyDownloadQueue_MojoSetupHack(Config conf, const uns
|
|||||||
case 4:
|
case 4:
|
||||||
msg += "zlib error";
|
msg += "zlib error";
|
||||||
break;
|
break;
|
||||||
|
case 5:
|
||||||
|
msg += "failed to set timestamp";
|
||||||
|
msg_type = MSGTYPE_WARNING;
|
||||||
|
bFailed = false;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
msg += "unknown error";
|
msg += "unknown error";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
msg += ")";
|
msg += ")";
|
||||||
|
|
||||||
msgQueue.push(Message(msg + " " + path_tmp.string(), MSGTYPE_ERROR, msg_prefix));
|
msgQueue.push(Message(msg + " " + path_tmp.string(), msg_type, msg_prefix));
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
if (bFailed)
|
||||||
|
continue;
|
||||||
|
|
||||||
if (boost::filesystem::exists(path_tmp) && boost::filesystem::is_regular_file(path_tmp))
|
if (boost::filesystem::exists(path_tmp) && boost::filesystem::is_regular_file(path_tmp))
|
||||||
{
|
{
|
||||||
if (!boost::filesystem::remove(path_tmp))
|
if (!boost::filesystem::remove(path_tmp))
|
||||||
@ -4961,7 +5009,6 @@ void Downloader::processGalaxyDownloadQueue_MojoSetupHack(Config conf, const uns
|
|||||||
msgQueue.push(Message(path_tmp.string() + ": Failed to delete", MSGTYPE_ERROR, msg_prefix));
|
msgQueue.push(Message(path_tmp.string() + ": Failed to delete", MSGTYPE_ERROR, msg_prefix));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Set file permission
|
// Set file permission
|
||||||
boost::filesystem::perms permissions = ZipUtil::getBoostFilePermission(zfe.file_attributes);
|
boost::filesystem::perms permissions = ZipUtil::getBoostFilePermission(zfe.file_attributes);
|
||||||
|
@ -481,6 +481,7 @@ zipCDEntry ZipUtil::readZipCDEntry(std::istream *stream)
|
|||||||
returns 2 if compression method is unsupported
|
returns 2 if compression method is unsupported
|
||||||
returns 3 if output file could not be created
|
returns 3 if output file could not be created
|
||||||
returns 4 if zlib error
|
returns 4 if zlib error
|
||||||
|
returns 5 if failed to set timestamp
|
||||||
*/
|
*/
|
||||||
int ZipUtil::extractFile(const std::string& input_file_path, const std::string& output_file_path)
|
int ZipUtil::extractFile(const std::string& input_file_path, const std::string& output_file_path)
|
||||||
{
|
{
|
||||||
@ -533,7 +534,15 @@ int ZipUtil::extractFile(const std::string& input_file_path, const std::string&
|
|||||||
output_file.close();
|
output_file.close();
|
||||||
|
|
||||||
if (cd.timestamp > 0)
|
if (cd.timestamp > 0)
|
||||||
boost::filesystem::last_write_time(output_file_path, cd.timestamp);
|
{
|
||||||
|
boost::system::error_code ec;
|
||||||
|
boost::filesystem::last_write_time(output_file_path, cd.timestamp, ec);
|
||||||
|
if (ec)
|
||||||
|
{
|
||||||
|
// Failed to set timestamp
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user