From 4be20db670bbda46678de7d762598b9971f3e4fe Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Tue, 22 Apr 2014 16:07:01 +0200 Subject: [PATCH] Propagator: Add makeConflictFileName function --- src/mirall/propagator_legacy.cpp | 12 +++--------- src/mirall/propagator_qnam.cpp | 24 +++++++++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/mirall/propagator_legacy.cpp b/src/mirall/propagator_legacy.cpp index 2aeada27b..d3d94989c 100644 --- a/src/mirall/propagator_legacy.cpp +++ b/src/mirall/propagator_legacy.cpp @@ -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()); diff --git a/src/mirall/propagator_qnam.cpp b/src/mirall/propagator_qnam.cpp index 800fad23c..436515446 100644 --- a/src/mirall/propagator_qnam.cpp +++ b/src/mirall/propagator_qnam.cpp @@ -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());