diff --git a/src/mirall/csyncthread.cpp b/src/mirall/csyncthread.cpp index b9e9eb4b1..c60e2464c 100644 --- a/src/mirall/csyncthread.cpp +++ b/src/mirall/csyncthread.cpp @@ -137,11 +137,12 @@ void CSyncThread::run() wStats->seenFiles = 0; wStats->conflicts = 0; wStats->error = 0; + const char *statedb = 0; _mutex.lock(); if( csync_create(&csync, - _source.toLocal8Bit().data(), - _target.toLocal8Bit().data()) < 0 ) { + _source.toLocal8Bit().data(), + _target.toLocal8Bit().data()) < 0 ) { emit csyncError( tr("CSync create failed.") ); } // FIXME: Check if we really need this stringcopy! @@ -214,6 +215,17 @@ void CSyncThread::run() goto cleanup; } + // After csync_init the statedb file name can be emitted + statedb = csync_get_statedb_file( csync ); + if( statedb ) { + QString stateDbFile = QString::fromUtf8(statedb); + free((void*)statedb); + + emit csyncStateDbFile( stateDbFile ); + } else { + qDebug() << "WRN: Unable to get csync statedb file name"; + } + qDebug() << "############################################################### >>"; if( csync_update(csync) < 0 ) { emit csyncError(tr("CSync Update failed.")); @@ -240,7 +252,6 @@ void CSyncThread::run() emit csyncError(tr("Local filesystem problems. Better disable Syncing and check.")); goto cleanup; } - qDebug() << " ..... Local walk finished: " << walkTime.elapsed(); // emit the treewalk results. Do not touch the wStats after this. emit treeWalkResult(wStats); @@ -248,6 +259,7 @@ void CSyncThread::run() _mutex.lock(); if( _localCheckOnly ) { _mutex.unlock(); + qDebug() << " ..... Local only walk finished: " << walkTime.elapsed(); // we have to go out here as its local check only. goto cleanup; } else { diff --git a/src/mirall/csyncthread.h b/src/mirall/csyncthread.h index 152fe398d..c4836cfed 100644 --- a/src/mirall/csyncthread.h +++ b/src/mirall/csyncthread.h @@ -68,7 +68,9 @@ public: signals: void treeWalkResult(WalkStats*); - void csyncError(const QString&); + void csyncError( const QString& ); + + void csyncStateDbFile( const QString& ); private: static int getauth(const char *prompt, diff --git a/src/mirall/folder.cpp b/src/mirall/folder.cpp index adeff3449..b3cdb1f7d 100644 --- a/src/mirall/folder.cpp +++ b/src/mirall/folder.cpp @@ -262,5 +262,10 @@ QString Folder::backend() const return _backend; } +void Folder::wipe() +{ + +} + } // namespace Mirall diff --git a/src/mirall/folder.h b/src/mirall/folder.h index dd66c5bf7..8cc57dc8d 100644 --- a/src/mirall/folder.h +++ b/src/mirall/folder.h @@ -129,6 +129,11 @@ public: */ QString backend() const; + /** + * This is called if the sync folder definition is removed. Do cleanups here. + */ + virtual void wipe(); + QIcon icon( int size ) const; QTimer *_pollTimer; diff --git a/src/mirall/folderman.cpp b/src/mirall/folderman.cpp index 9f440c890..b351009f0 100644 --- a/src/mirall/folderman.cpp +++ b/src/mirall/folderman.cpp @@ -337,6 +337,7 @@ void FolderMan::removeFolder( const QString& alias ) if( _folderMap.contains( alias )) { qDebug() << "Removing " << alias; Folder *f = _folderMap.take( alias ); + f->wipe(); f->deleteLater(); } else { qDebug() << "!! Can not remove " << alias << ", not in folderMap."; diff --git a/src/mirall/owncloudfolder.cpp b/src/mirall/owncloudfolder.cpp index 84170b7b3..fde4e70d6 100644 --- a/src/mirall/owncloudfolder.cpp +++ b/src/mirall/owncloudfolder.cpp @@ -68,6 +68,7 @@ ownCloudFolder::ownCloudFolder(const QString &alias, ownCloudFolder::~ownCloudFolder() { + } #ifndef USE_INOTIFY @@ -144,6 +145,7 @@ void ownCloudFolder::startSync(const QStringList &pathList) QObject::connect(_csync, SIGNAL(finished()), SLOT(slotCSyncFinished())); QObject::connect(_csync, SIGNAL(terminated()), SLOT(slotCSyncTerminated())); connect(_csync, SIGNAL(csyncError(const QString)), SLOT(slotCSyncError(const QString))); + connect(_csync, SIGNAL(csyncStateDbFile(QString)), SLOT(slotCsyncStateDbFile(QString))); connect( _csync, SIGNAL(treeWalkResult(WalkStats*)), this, SLOT(slotThreadTreeWalkResult(WalkStats*))); @@ -200,6 +202,12 @@ void ownCloudFolder::slotCSyncError(const QString& err) _csyncError = true; } +void ownCloudFolder::slotCsyncStateDbFile( const QString& file ) +{ + qDebug() << "Got csync statedb file: " << file; + _csyncStateDbFile = file; +} + void ownCloudFolder::slotCSyncTerminated() { // do not ask csync here for reasons. @@ -253,5 +261,31 @@ void ownCloudFolder::slotTerminateSync() } } +// This removes the csync File database if the sync folder definition is removed +// permanentely. This is needed to provide a clean startup again in case another +// local folder is synced to the same ownCloud. +// See http://bugs.owncloud.org/thebuggenie/owncloud/issues/oc-788 +void ownCloudFolder::wipe() +{ + if( !_csyncStateDbFile.isEmpty() ) { + QFile file(_csyncStateDbFile); + if( file.exists() ) { + if( !file.remove()) { + qDebug() << "WRN: Failed to remove existing csync StateDB " << _csyncStateDbFile; + } else { + qDebug() << "wipe: Removed csync StateDB " << _csyncStateDbFile; + } + } else { + qDebug() << "WRN: statedb is empty, can not remove."; + } + // Check if the tmp database file also exists + QString ctmpName = _csyncStateDbFile + ".ctmp"; + QFile ctmpFile( ctmpName ); + if( ctmpFile.exists() ) { + ctmpFile.remove(); + } + } +} + } // ns diff --git a/src/mirall/owncloudfolder.h b/src/mirall/owncloudfolder.h index 031da91ce..4647d9bc4 100644 --- a/src/mirall/owncloudfolder.h +++ b/src/mirall/owncloudfolder.h @@ -38,6 +38,8 @@ public: virtual bool isBusy() const; virtual void startSync(const QStringList &pathList); + virtual void wipe(); + public slots: void startSync(); void slotTerminateSync(); @@ -48,6 +50,7 @@ private slots: void slotCSyncFinished(); void slotThreadTreeWalkResult( WalkStats* ); void slotCSyncTerminated(); + void slotCsyncStateDbFile(const QString&); #ifndef USE_INOTIFY void slotPollTimerRemoteCheck(); @@ -62,6 +65,7 @@ private: QStringList _errors; bool _csyncError; ulong _lastSeenFiles; + QString _csyncStateDbFile; }; }