From e1a48e3c33161d47ad7f30b0dea30bd350c98b1b Mon Sep 17 00:00:00 2001 From: Klaas Freitag Date: Mon, 10 Oct 2016 16:55:24 +0200 Subject: [PATCH] Move the journal file name generation to the syncjournaldb class. As requested by Olivier. --- src/gui/folder.cpp | 1 + src/libsync/syncengine.cpp | 21 +-------------------- src/libsync/syncjournaldb.cpp | 19 ++++++++++++++++++- src/libsync/syncjournaldb.h | 3 +++ 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp index e240aa8cf..5ab6fbbe4 100644 --- a/src/gui/folder.cpp +++ b/src/gui/folder.cpp @@ -80,6 +80,7 @@ Folder::Folder(const FolderDefinition& definition, checkLocalPath(); _syncResult.setFolder(_definition.alias); + _journal.setAccountParameterForFilePath(path(), remoteUrl(), remotePath()); _engine.reset(new SyncEngine(_accountState->account(), path(), remoteUrl(), remotePath(), &_journal)); // pass the setting if hidden files are to be ignored, will be read in csync_update diff --git a/src/libsync/syncengine.cpp b/src/libsync/syncengine.cpp index ddb695184..ace7dea5d 100644 --- a/src/libsync/syncengine.cpp +++ b/src/libsync/syncengine.cpp @@ -92,9 +92,7 @@ SyncEngine::SyncEngine(AccountPtr account, const QString& localPath, csync_create(&_csync_ctx, localPath.toUtf8().data(), url_string.toUtf8().data()); - const QString dbFile = this->journalDbFilePath(); - _journal->setDatabaseFilePath( dbFile ); - Q_ASSERT(!dbFile.isEmpty()); + const QString dbFile = _journal->databaseFilePath(); csync_init(_csync_ctx, dbFile.toUtf8().data()); _excludedFiles.reset(new ExcludedFiles(&_csync_ctx->excludes)); @@ -116,23 +114,6 @@ SyncEngine::~SyncEngine() csync_destroy(_csync_ctx); } -QString SyncEngine::journalDbFilePath() const -{ - // localPath always has a trailing slash - QString dbFile(_localPath); - dbFile.append( QLatin1String(".sync_")); - // FIXME: Maybe it is better to only allow different hosts, without path component. - QString remoteUrlPath = _remoteUrl.toString(); - if( _remotePath != QLatin1String("/") ) { - remoteUrlPath.append(_remotePath); - } - QByteArray ba = QCryptographicHash::hash( remoteUrlPath.toUtf8(), QCryptographicHash::Md5); - dbFile.append( ba.left(6).toHex() ); - dbFile.append(".db"); - - return dbFile; -} - //Convert an error code from csync to a user readable string. // Keep that function thread safe as it can be called from the sync thread or the main thread QString SyncEngine::csyncErrorToString(CSYNC_STATUS err) diff --git a/src/libsync/syncjournaldb.cpp b/src/libsync/syncjournaldb.cpp index 649ba7069..b3808eea8 100644 --- a/src/libsync/syncjournaldb.cpp +++ b/src/libsync/syncjournaldb.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include "ownsql.h" @@ -42,11 +43,27 @@ bool SyncJournalDb::exists() return (!_dbFile.isEmpty() && QFile::exists(_dbFile)); } +void SyncJournalDb::setAccountParameterForFilePath( const QString& localPath, const QUrl& remoteUrl, const QString& remotePath ) +{ + // localPath always has a trailing slash + _dbFile = localPath; + _dbFile.append( QLatin1String(".sync_")); + // FIXME: Maybe it is better to only allow different hosts, without path component. + QString remoteUrlPath = remoteUrl.toString(); + if( remotePath != QLatin1String("/") ) { + remoteUrlPath.append(remotePath); + } + QByteArray ba = QCryptographicHash::hash( remoteUrlPath.toUtf8(), QCryptographicHash::Md5); + _dbFile.append( ba.left(6).toHex() ); + _dbFile.append(".db"); +} + +#ifndef NDEBUG void SyncJournalDb::setDatabaseFilePath( const QString& dbFile) { _dbFile = dbFile; } - +#endif QString SyncJournalDb::databaseFilePath() { return _dbFile; diff --git a/src/libsync/syncjournaldb.h b/src/libsync/syncjournaldb.h index 893ba84c0..a9a7eab2f 100644 --- a/src/libsync/syncjournaldb.h +++ b/src/libsync/syncjournaldb.h @@ -56,7 +56,10 @@ public: void walCheckpoint(); QString databaseFilePath(); +#ifndef NDEBUG void setDatabaseFilePath( const QString& dbFile); +#endif + void setAccountParameterForFilePath(const QString& localPath, const QUrl &remoteUrl, const QString& remotePath ); static qint64 getPHash(const QString& );