CHUI-778: Now when conversation log and trascript files are moved they will not overwrite prior files with the same name. Instead the prior files will be stored as *.backup.
parent
57935506c2
commit
084ea74d43
|
|
@ -31,6 +31,8 @@
|
|||
#include "llnotificationsutil.h"
|
||||
#include "lltrans.h"
|
||||
|
||||
#include "boost/lexical_cast.hpp"
|
||||
|
||||
const int CONVERSATION_LIFETIME = 30; // lifetime of LLConversation is 30 days by spec
|
||||
|
||||
struct ConversationParams
|
||||
|
|
@ -382,13 +384,12 @@ bool LLConversationLog::moveLog(const std::string &originDirectory, const std::s
|
|||
{
|
||||
|
||||
std::string backupFileName;
|
||||
UINT backupFileCount = 0;
|
||||
unsigned backupFileCount = 0;
|
||||
|
||||
//Does the file exist in the current path
|
||||
if(LLFile::isfile(originDirectory))
|
||||
//Does the file exist in the current path, if it does lets move it
|
||||
if(LLFile::isfile(originDirectory))
|
||||
{
|
||||
|
||||
//File already exists so make a backup file
|
||||
//The target directory contains that file already, so lets store it
|
||||
if(LLFile::isfile(targetDirectory))
|
||||
{
|
||||
backupFileName = targetDirectory + ".backup";
|
||||
|
|
@ -396,19 +397,15 @@ bool LLConversationLog::moveLog(const std::string &originDirectory, const std::s
|
|||
//If needed store backup file as .backup1 etc.
|
||||
while(LLFile::isfile(backupFileName))
|
||||
{
|
||||
backupFileName = targetDirectory + ".backup";
|
||||
|
||||
if(backupFileCount)
|
||||
{
|
||||
backupFileName += backupFileCount;
|
||||
}
|
||||
++backupFileCount;
|
||||
backupFileName = targetDirectory + ".backup" + boost::lexical_cast<std::string>(backupFileCount);
|
||||
}
|
||||
|
||||
//Rename the file to its backup name so it is not overwritten
|
||||
LLFile::rename(targetDirectory, backupFileName);
|
||||
}
|
||||
|
||||
//Move the file from the current path to destination path
|
||||
//Move the file from the current path to target path
|
||||
if(LLFile::rename(originDirectory, targetDirectory) != 0)
|
||||
{
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -509,9 +509,12 @@ bool LLLogChat::moveTranscripts(const std::string originDirectory,
|
|||
{
|
||||
std::string newFullPath;
|
||||
bool movedAllTranscripts = true;
|
||||
std::string backupFileName;
|
||||
unsigned backupFileCount;
|
||||
|
||||
BOOST_FOREACH(const std::string& fullpath, listOfFilesToMove)
|
||||
{
|
||||
backupFileCount = 0;
|
||||
newFullPath = targetDirectory + fullpath.substr(originDirectory.length(), std::string::npos);
|
||||
|
||||
S32 retry_count = 0;
|
||||
|
|
@ -525,17 +528,20 @@ bool LLLogChat::moveTranscripts(const std::string originDirectory,
|
|||
LL_WARNS("LLLogChat::moveTranscripts") << "Problem renaming " << fullpath << " - errorcode: "
|
||||
<< result << " attempt " << retry_count << LL_ENDL;
|
||||
|
||||
if(retry_count >= 5)
|
||||
{
|
||||
LL_WARNS("LLLogChat::moveTranscripts") << "Failed to rename " << fullpath << LL_ENDL;
|
||||
return false;
|
||||
}
|
||||
|
||||
//If the file already exists in the new location, remove it then try again
|
||||
//The target directory contains that file already, so lets store it
|
||||
if(LLFile::isfile(newFullPath))
|
||||
{
|
||||
LLFile::remove(newFullPath);
|
||||
LL_WARNS("LLLogChat::moveTranscripts") << "File already exists " << fullpath << LL_ENDL;
|
||||
backupFileName = newFullPath + ".backup";
|
||||
|
||||
//If needed store backup file as .backup1 etc.
|
||||
while(LLFile::isfile(backupFileName))
|
||||
{
|
||||
++backupFileCount;
|
||||
backupFileName = newFullPath + ".backup" + boost::lexical_cast<std::string>(backupFileCount);
|
||||
}
|
||||
|
||||
//Rename the file to its backup name so it is not overwritten
|
||||
LLFile::rename(newFullPath, backupFileName);
|
||||
}
|
||||
|
||||
ms_sleep(100);
|
||||
|
|
|
|||
Loading…
Reference in New Issue