From 12148b5c9b5fd5dc95dc8d42a61f8985e734d2c8 Mon Sep 17 00:00:00 2001 From: Daniel Molkentin Date: Thu, 6 Jun 2013 17:59:50 +0200 Subject: [PATCH] remove journal when adding a new sync on an existing folder --- src/mirall/application.cpp | 2 ++ src/mirall/folderman.cpp | 21 ++++++++++++++++++++- src/mirall/folderman.h | 7 +++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/mirall/application.cpp b/src/mirall/application.cpp index fcdac4424..f8048ed71 100644 --- a/src/mirall/application.cpp +++ b/src/mirall/application.cpp @@ -698,6 +698,8 @@ void Application::slotAddFolder() _folderMan->setSyncEnabled(true); // do start sync again. if( goodData ) { + if (!FolderMan::ensureJournalGone( sourceFolder )) + return; _folderMan->addFolderDefinition( backend, alias, sourceFolder, targetPath, onlyThisLAN ); Folder *f = _folderMan->setupFolderFromConfigFile( alias ); if( f ) { diff --git a/src/mirall/folderman.cpp b/src/mirall/folderman.cpp index 0c4393553..0053b1217 100644 --- a/src/mirall/folderman.cpp +++ b/src/mirall/folderman.cpp @@ -27,6 +27,7 @@ #endif #include +#include #include namespace Mirall { @@ -125,6 +126,24 @@ void FolderMan::wipeAllJournals() } } +bool FolderMan::ensureJournalGone(const QString &localPath) +{ + + // remove old .csync_journal file + QString stateDbFile = localPath+QLatin1String(".csync_journal.db"); + while (!QFile::remove(stateDbFile)) { + int ret = QMessageBox::warning(0, tr("Could not reset folder state"), + tr("An old sync journal '%1' was found, " + "but could not be removed. Please make sure " + "that no application is currently using it.") + .arg(QDir::fromNativeSeparators(stateDbFile)), + QMessageBox::Retry|QMessageBox::Abort); + if (ret == QMessageBox::Abort) { + return 0; + } + } +} + void FolderMan::terminateCurrentSync() { if( !_currentSyncFolder.isEmpty() ) { @@ -243,7 +262,7 @@ Folder* FolderMan::setupFolderFromConfigFile(const QString &file) { folder->setConfigFile(file); } else { qWarning() << "unknown backend" << backend; - return NULL; + return 0; } } diff --git a/src/mirall/folderman.h b/src/mirall/folderman.h index b7a69df07..1733f84f5 100644 --- a/src/mirall/folderman.h +++ b/src/mirall/folderman.h @@ -76,6 +76,13 @@ public: */ void wipeAllJournals(); + /** + * Ensures that a given directory does not contain a .csync_journal. + * + * @returns false if the journal could not be removed, false otherwise. + */ + static bool ensureJournalGone(const QString &path); + /** * Creates a new and empty local directory. */