FolderMan: Delete old journal file when adding folder. #2606

This commit is contained in:
Christian Kamm 2014-12-11 12:28:01 +01:00
parent 4559bb5553
commit 84e5ad7346
4 changed files with 23 additions and 12 deletions

View file

@ -202,10 +202,9 @@ void AccountSettings::slotFolderWizardAccepted()
QStringList selectiveSyncBlackList
= folderWizard->property("selectiveSyncBlackList").toStringList();
if (!FolderMan::ensureJournalGone( sourceFolder ))
if (!folderMan->addFolderDefinition(alias, sourceFolder, targetPath, selectiveSyncBlackList))
return;
folderMan->addFolderDefinition(alias, sourceFolder, targetPath, selectiveSyncBlackList );
Folder *f = folderMan->setupFolderFromConfigFile( alias );
slotAddFolder( f );
folderMan->setSyncEnabled(true);

View file

@ -234,6 +234,7 @@ bool FolderMan::ensureJournalGone(const QString &localPath)
// remove old .csync_journal file
QString stateDbFile = localPath+QLatin1String("/.csync_journal.db");
while (QFile::exists(stateDbFile) && !QFile::remove(stateDbFile)) {
qDebug() << "Could not remove old db file at" << 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 "
@ -650,9 +651,12 @@ void FolderMan::slotFolderSyncFinished( const SyncResult& )
QTimer::singleShot(200, this, SLOT(slotStartScheduledFolderSync()));
}
void FolderMan::addFolderDefinition(const QString& alias, const QString& sourceFolder,
const QString& targetPath, const QStringList &selectiveSyncBlackList )
bool FolderMan::addFolderDefinition(const QString& alias, const QString& sourceFolder,
const QString& targetPath, const QStringList& selectiveSyncBlackList)
{
if (! ensureJournalGone(sourceFolder))
return false;
QString escapedAlias = escapeAlias(alias);
// Create a settings file named after the alias
QSettings settings( _folderConfigPath + QLatin1Char('/') + escapedAlias, QSettings::IniFormat);
@ -664,6 +668,8 @@ void FolderMan::addFolderDefinition(const QString& alias, const QString& sourceF
settings.setValue(QLatin1String("connection"), Theme::instance()->appName());
settings.setValue(QLatin1String("blackList"), selectiveSyncBlackList);
settings.sync();
return true;
}
Folder *FolderMan::folderForPath(const QString &path)

View file

@ -49,9 +49,13 @@ public:
* QString alias
* QString sourceFolder on local machine
* QString targetPath on remote
*
* Ensures any existing journal in the sourceFolder is deleted.
* Returns true on success.
*/
void addFolderDefinition(const QString&, const QString&, const QString& ,
const QStringList &selectiveSyncBlacklist = QStringList() );
bool addFolderDefinition(const QString& alias, const QString& sourceFolder,
const QString& targetPath,
const QStringList& selectiveSyncBlacklist = QStringList());
/** Returns the folder which the file or directory stored in path is in */
Folder* folderForPath(const QString& path);

View file

@ -437,17 +437,19 @@ void OwncloudSetupWizard::slotAssistantFinished( int result )
// 2.1: startFromScratch: (Re)move local data, clean slate sync
if (startFromScratch) {
if (ensureStartFromScratch(localFolder)) {
folderMan->addFolderDefinition(Theme::instance()->appName(),
localFolder, _remoteFolder, _ocWizard->blacklist() );
_ocWizard->appendToConfigurationLog(tr("<font color=\"green\"><b>Local sync folder %1 successfully created!</b></font>").arg(localFolder));
if (folderMan->addFolderDefinition(Theme::instance()->appName(),
localFolder, _remoteFolder, _ocWizard->blacklist() )) {
_ocWizard->appendToConfigurationLog(tr("<font color=\"green\"><b>Local sync folder %1 successfully created!</b></font>").arg(localFolder));
}
replaceDefaultAccountWith(newAccount);
}
}
// 2.2: Reinit: Remove journal and start a sync
else {
folderMan->addFolderDefinition(Theme::instance()->appName(),
localFolder, _remoteFolder, _ocWizard->blacklist() );
_ocWizard->appendToConfigurationLog(tr("<font color=\"green\"><b>Local sync folder %1 successfully created!</b></font>").arg(localFolder));
if (folderMan->addFolderDefinition(Theme::instance()->appName(),
localFolder, _remoteFolder, _ocWizard->blacklist() )) {
_ocWizard->appendToConfigurationLog(tr("<font color=\"green\"><b>Local sync folder %1 successfully created!</b></font>").arg(localFolder));
}
replaceDefaultAccountWith(newAccount);
}
}