From 84ede3f01fe89c809fa761ff53433a8bef3a11a8 Mon Sep 17 00:00:00 2001 From: Klaas Freitag Date: Fri, 2 Sep 2016 16:12:43 +0200 Subject: [PATCH] Make sync journal name generating a method of SyncJournal. Before it was in Folder, however, the command line client does not have the Folder class. To not duplicate code, the function to generate the sync journal name went to SyncEngine class. --- src/cmd/cmd.cpp | 3 --- src/gui/folder.cpp | 19 ------------------- src/gui/folder.h | 5 ----- src/gui/folderman.cpp | 2 +- src/libsync/syncengine.cpp | 20 +++++++++++++++++++- src/libsync/syncengine.h | 2 ++ 6 files changed, 22 insertions(+), 29 deletions(-) diff --git a/src/cmd/cmd.cpp b/src/cmd/cmd.cpp index f404094fe..c15fe5013 100644 --- a/src/cmd/cmd.cpp +++ b/src/cmd/cmd.cpp @@ -271,7 +271,6 @@ void selectiveSyncFixup(OCC::SyncJournalDb *journal, const QStringList &newList) } } - int main(int argc, char **argv) { QCoreApplication app(argc, argv); @@ -437,8 +436,6 @@ restart_sync: Cmd cmd; SyncJournalDb db; - // FIXME: Use new MD5 based name - db.setDatabaseFilePath(options.source_dir + ".csync_journal.db"); if (!selectiveSyncList.empty()) { selectiveSyncFixup(&db, selectiveSyncList); diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp index fba4f531e..e240aa8cf 100644 --- a/src/gui/folder.cpp +++ b/src/gui/folder.cpp @@ -81,9 +81,6 @@ Folder::Folder(const FolderDefinition& definition, _syncResult.setFolder(_definition.alias); - // initalize the journal with the file path of the journal - _journal.setDatabaseFilePath( journalDbFilePath() ); - _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 _engine->setIgnoreHiddenFiles(_definition.ignoreHiddenFiles); @@ -122,22 +119,6 @@ Folder::~Folder() _engine.reset(); } -QString Folder::journalDbFilePath() const -{ - // localPath always has a trailing slash - QString dbFile = path(); - 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; -} void Folder::checkLocalPath() { diff --git a/src/gui/folder.h b/src/gui/folder.h index 52c699634..40ff6deb1 100644 --- a/src/gui/folder.h +++ b/src/gui/folder.h @@ -163,11 +163,6 @@ public: void setDirtyNetworkLimits(); - /** - * The file path of the journal db file, calculated from remote url - */ - QString journalDbFilePath() const; - /** * Ignore syncing of hidden files or not. This is defined in the * folder definition diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp index 1a62f33d7..7a9e1db5b 100644 --- a/src/gui/folderman.cpp +++ b/src/gui/folderman.cpp @@ -815,7 +815,7 @@ Folder* FolderMan::addFolderInternal(FolderDefinition folderDefinition, AccountS auto folder = new Folder(folderDefinition, accountState, this ); - if (!ensureJournalGone(folder->journalDbFilePath())) { + if (!ensureJournalGone(folder->journalDb()->databaseFilePath())) { delete folder; return 0; } diff --git a/src/libsync/syncengine.cpp b/src/libsync/syncengine.cpp index 969670b0f..ddb695184 100644 --- a/src/libsync/syncengine.cpp +++ b/src/libsync/syncengine.cpp @@ -92,7 +92,8 @@ SyncEngine::SyncEngine(AccountPtr account, const QString& localPath, csync_create(&_csync_ctx, localPath.toUtf8().data(), url_string.toUtf8().data()); - const QString dbFile = _journal->databaseFilePath(); + const QString dbFile = this->journalDbFilePath(); + _journal->setDatabaseFilePath( dbFile ); Q_ASSERT(!dbFile.isEmpty()); csync_init(_csync_ctx, dbFile.toUtf8().data()); @@ -115,6 +116,23 @@ 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/syncengine.h b/src/libsync/syncengine.h index f9e8ba3f6..d7b5c5b5d 100644 --- a/src/libsync/syncengine.h +++ b/src/libsync/syncengine.h @@ -166,6 +166,8 @@ private slots: private: void handleSyncError(CSYNC *ctx, const char *state); + QString journalDbFilePath() const; + static int treewalkLocal( TREE_WALK_FILE*, void *); static int treewalkRemote( TREE_WALK_FILE*, void *); int treewalkFile( TREE_WALK_FILE*, bool );