Don't return error code if a file to be removed does not exist.
Improved error handling in addons.xml download.
This commit is contained in:
parent
472274561d
commit
da7bad92e6
@ -1037,11 +1037,16 @@ void FileManager::checkAndCreateDirForAddons(const std::string &dir)
|
|||||||
} // checkAndCreateDirForAddons
|
} // checkAndCreateDirForAddons
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
/** Removes the specified file, returns true if successful, or false
|
/** Removes the specified file.
|
||||||
* if the file is not a regular file or can not be removed.
|
* \return True if successful, or false if the file is not a regular file or
|
||||||
|
* can not be removed.
|
||||||
*/
|
*/
|
||||||
bool FileManager::removeFile(const std::string &name) const
|
bool FileManager::removeFile(const std::string &name) const
|
||||||
{
|
{
|
||||||
|
// If the file does not exists, everything is fine
|
||||||
|
if(!fileExists(name))
|
||||||
|
return true;
|
||||||
|
|
||||||
struct stat mystat;
|
struct stat mystat;
|
||||||
if(stat(name.c_str(), &mystat) < 0) return false;
|
if(stat(name.c_str(), &mystat) < 0) return false;
|
||||||
if( S_ISREG(mystat.st_mode))
|
if( S_ISREG(mystat.st_mode))
|
||||||
|
1087
src/io/file_manager.cpp~
Normal file
1087
src/io/file_manager.cpp~
Normal file
File diff suppressed because it is too large
Load Diff
@ -227,14 +227,20 @@ namespace Online
|
|||||||
Log::info("HTTPRequest", "Download successful.");
|
Log::info("HTTPRequest", "Download successful.");
|
||||||
// The behaviour of rename is unspecified if the target
|
// The behaviour of rename is unspecified if the target
|
||||||
// file should already exist - so remove it.
|
// file should already exist - so remove it.
|
||||||
file_manager->removeFile(m_filename);
|
bool ok = file_manager->removeFile(m_filename);
|
||||||
|
if(!ok)
|
||||||
|
{
|
||||||
|
Log::error("addons",
|
||||||
|
"Could not removed existing addons.xml file.");
|
||||||
|
m_curl_code = CURLE_WRITE_ERROR;
|
||||||
|
}
|
||||||
int ret = rename((m_filename+".part").c_str(),
|
int ret = rename((m_filename+".part").c_str(),
|
||||||
m_filename.c_str() );
|
m_filename.c_str() );
|
||||||
// In case of an error, set the status to indicate this
|
// In case of an error, set the status to indicate this
|
||||||
if(ret!=0)
|
if(ret!=0)
|
||||||
{
|
{
|
||||||
if(UserConfigParams::logAddons())
|
Log::error("addons",
|
||||||
Log::error("addons", "Could not rename downloaded file!");
|
"Could not rename downloaded addons.xml file!");
|
||||||
m_curl_code = CURLE_WRITE_ERROR;
|
m_curl_code = CURLE_WRITE_ERROR;
|
||||||
}
|
}
|
||||||
} // m_curl_code ==CURLE_OK
|
} // m_curl_code ==CURLE_OK
|
||||||
|
Loading…
Reference in New Issue
Block a user