Propagator: Add makeConflictFileName function

This commit is contained in:
Markus Goetz 2014-04-22 16:07:01 +02:00
parent 707c6fcc5d
commit 4be20db670
2 changed files with 18 additions and 18 deletions

View file

@ -437,6 +437,8 @@ void PropagateDownloadFileLegacy::notify_status_cb(void* userdata, ne_session_st
}
}
extern QString makeConflictFileName(QString &fn, QDateTime dt); // _qnam.cpp
void PropagateDownloadFileLegacy::start()
{
if (_propagator->_abortRequested.fetchAndAddRelaxed(0))
@ -564,15 +566,7 @@ void PropagateDownloadFileLegacy::start()
//In case of conflict, make a backup of the old file
if (isConflict) {
QFile f(fn);
QString conflictFileName(fn);
// Add _conflict-XXXX before the extention.
int dotLocation = conflictFileName.lastIndexOf('.');
// If no extention, add it at the end (take care of cases like foo/.hidden or foo.bar/file)
if (dotLocation <= conflictFileName.lastIndexOf('/') + 1) {
dotLocation = conflictFileName.size();
}
QString timeString = Utility::qDateTimeFromTime_t(_item._modtime).toString("yyyyMMdd-hhmmss");
conflictFileName.insert(dotLocation, "_conflict-" + timeString);
QString conflictFileName = makeConflictFileName(fn, Utility::qDateTimeFromTime_t(_item._modtime));
if (!f.rename(conflictFileName)) {
//If the rename fails, don't replace it.
done(SyncFileItem::NormalError, f.errorString());

View file

@ -524,6 +524,20 @@ void PropagateDownloadFileQNAM::slotGetFinished()
downloadFinished();
}
QString makeConflictFileName(QString &fn, QDateTime dt)
{
QString conflictFileName(fn);
// Add _conflict-XXXX before the extention.
int dotLocation = conflictFileName.lastIndexOf('.');
// If no extention, add it at the end (take care of cases like foo/.hidden or foo.bar/file)
if (dotLocation <= conflictFileName.lastIndexOf('/') + 1) {
dotLocation = conflictFileName.size();
}
QString timeString = dt.toString("yyyyMMdd-hhmmss");
conflictFileName.insert(dotLocation, "_conflict-" + timeString);
return conflictFileName;
}
void PropagateDownloadFileQNAM::downloadFinished()
{
@ -535,15 +549,7 @@ void PropagateDownloadFileQNAM::downloadFinished()
//In case of conflict, make a backup of the old file
if (isConflict) {
QFile f(fn);
QString conflictFileName(fn);
// Add _conflict-XXXX before the extention.
int dotLocation = conflictFileName.lastIndexOf('.');
// If no extention, add it at the end (take care of cases like foo/.hidden or foo.bar/file)
if (dotLocation <= conflictFileName.lastIndexOf('/') + 1) {
dotLocation = conflictFileName.size();
}
QString timeString = Utility::qDateTimeFromTime_t(_item._modtime).toString("yyyyMMdd-hhmmss");
conflictFileName.insert(dotLocation, "_conflict-" + timeString);
QString conflictFileName = makeConflictFileName(fn, Utility::qDateTimeFromTime_t(_item._modtime));
if (!f.rename(conflictFileName)) {
//If the rename fails, don't replace it.
done(SyncFileItem::NormalError, f.errorString());