Make the sync journal file name a method of the Folder class.

The sync journal name has a dependency on the remote url now.
This commit is contained in:
Klaas Freitag 2016-09-02 12:29:21 +02:00
parent f3cfd2b70b
commit e46fad52bb
5 changed files with 39 additions and 23 deletions

View file

@ -81,6 +81,9 @@ 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);
@ -119,6 +122,23 @@ 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()
{
const QFileInfo fi(_definition.localPath);

View file

@ -163,6 +163,11 @@ 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

@ -255,20 +255,18 @@ int FolderMan::setupFoldersMigration()
return _folderMap.size();
}
bool FolderMan::ensureJournalGone(const QString &localPath, const QString& remoteUrl)
bool FolderMan::ensureJournalGone( const QString& journalDbFile )
{
Q_UNUSED(remoteUrl);
// FIXME move this to UI, not libowncloudsync
// FIXME use the remoteUrl to remove the MD5-journal name
// 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;
while (QFile::exists(journalDbFile) && !QFile::remove(journalDbFile)) {
qDebug() << "Could not remove old db file at" << journalDbFile;
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(QDir::cleanPath(stateDbFile))),
.arg(QDir::fromNativeSeparators(QDir::cleanPath(journalDbFile))),
QMessageBox::Retry|QMessageBox::Abort);
if (ret == QMessageBox::Abort) {
return false;
@ -798,12 +796,8 @@ void FolderMan::slotFolderSyncFinished( const SyncResult& )
Folder* FolderMan::addFolder(AccountState* accountState, const FolderDefinition& folderDefinition)
{
// FIXME journal name
if (!ensureJournalGone(folderDefinition.localPath, accountState->account()->url().toString() + folderDefinition.targetPath)) {
return 0;
}
auto folder = addFolderInternal(folderDefinition, accountState);
if(folder) {
folder->saveToSettings();
emit folderSyncStateChange(folder);
@ -823,6 +817,11 @@ Folder* FolderMan::addFolderInternal(FolderDefinition folderDefinition, AccountS
auto folder = new Folder(folderDefinition, accountState, this );
if (!ensureJournalGone(folder->journalDbFilePath())) {
delete folder;
return 0;
}
qDebug() << "Adding folder to Folder Map " << folder << folder->alias();
_folderMap[folder->alias()] = folder;
if (folder->syncPaused()) {

View file

@ -78,7 +78,7 @@ public:
*
* @returns false if the journal could not be removed, true otherwise.
*/
static bool ensureJournalGone(const QString &path, const QString &remoteUrl);
static bool ensureJournalGone(const QString& journalDbFile);
/** Creates a new and empty local directory. */
bool startFromScratch( const QString& );

View file

@ -90,18 +90,10 @@ SyncEngine::SyncEngine(AccountPtr account, const QString& localPath,
#endif
url_string = Utility::toCSyncScheme(url_string);
// localPath always has a trailing slash
QString dbFile = localPath;
dbFile.append( QLatin1String(".csync_"));
// FIXME: Make sure this remoteUrlPath is equal to the one calculated in FolderMan::ensureJournalGone
// FIXME: Maybe it is better to only allow different hosts, without path component.
QString remoteUrlPath = _remoteUrl.toString()+_remotePath;
QByteArray ba = QCryptographicHash::hash( remoteUrlPath.toUtf8(), QCryptographicHash::Md5);
dbFile.append( ba.left(6).toHex() );
_journal->setDatabaseFilePath(dbFile);
csync_create(&_csync_ctx, localPath.toUtf8().data(), url_string.toUtf8().data());
const QString dbFile = _journal->databaseFilePath();
Q_ASSERT(!dbFile.isEmpty());
csync_init(_csync_ctx, dbFile.toUtf8().data());
_excludedFiles.reset(new ExcludedFiles(&_csync_ctx->excludes));