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.
This commit is contained in:
Klaas Freitag 2016-09-02 16:12:43 +02:00
parent 2daf895e43
commit 84ede3f01f
6 changed files with 22 additions and 29 deletions

View file

@ -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);

View file

@ -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()
{

View file

@ -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

View file

@ -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;
}

View file

@ -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)

View file

@ -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 );