diff --git a/src/mirall/folder.cpp b/src/mirall/folder.cpp index d501f45cc..3bddf883a 100644 --- a/src/mirall/folder.cpp +++ b/src/mirall/folder.cpp @@ -30,6 +30,7 @@ namespace Mirall { Folder::Folder(const QString &alias, const QString &path, QObject *parent) : QObject(parent), + _errorCount(0), _path(path), _pollTimer(new QTimer(this)), _pollInterval(DEFAULT_POLL_INTERVAL_SEC), @@ -112,13 +113,37 @@ void Folder::setPollInterval(int seconds) _pollInterval = seconds; } +int Folder::errorCount() +{ + return _errorCount; +} + +void Folder::resetErrorCount() +{ + _errorCount = 0; +} + +void Folder::incrementErrorCount() +{ + // if the error count gets higher than three, the interval timer + // of the watcher is doubled. + _errorCount++; + if( _errorCount > 1 ) { + int interval = _watcher->eventInterval(); + int newInt = 2*interval; + qDebug() << "Set new watcher interval to " << newInt; + _watcher->setEventInterval( newInt ); + _errorCount = 0; + } +} + void Folder::evaluateSync(const QStringList &pathList) { - if (!_online && onlyOnlineEnabled()) { - qDebug() << "*" << alias() << "sync skipped, not online"; - return; - } - startSync(pathList); + if (!_online && onlyOnlineEnabled()) { + qDebug() << "*" << alias() << "sync skipped, not online"; + return; + } + startSync(pathList); } void Folder::slotPollTimerTimeout() diff --git a/src/mirall/folder.h b/src/mirall/folder.h index 2a3b3f3ce..f9669367c 100644 --- a/src/mirall/folder.h +++ b/src/mirall/folder.h @@ -88,6 +88,16 @@ public: void setOnlyThisLANEnabled(bool enabled); + /** + * error counter, stop syncing after the counter reaches a certain + * number. + */ + int errorCount(); + + void resetErrorCount(); + + void incrementErrorCount(); + protected: /** * The minimum amounts of seconds to wait before @@ -108,6 +118,7 @@ signals: protected: FolderWatcher *_watcher; + int _errorCount; private: diff --git a/src/mirall/sitecopyfolder.cpp b/src/mirall/sitecopyfolder.cpp index aca4fd4e8..e8e0fe26e 100644 --- a/src/mirall/sitecopyfolder.cpp +++ b/src/mirall/sitecopyfolder.cpp @@ -29,8 +29,8 @@ namespace Mirall { const QString &secondPath, QObject *parent) : Folder(alias, path, parent), - _SiteCopy(new QProcess(this)), - _syncCount(0) + _SiteCopy(new QProcess(this)), + _syncCount(0) { QObject::connect(_SiteCopy, SIGNAL(readyReadStandardOutput()), SLOT(slotReadyReadStandardOutput())); @@ -112,15 +112,19 @@ void SiteCopyFolder::slotFinished(int exitCode, QProcess::ExitStatus exitStatus) if( exitCode == -1 ) { qDebug() << "Configuration Error, stop processing."; - emit( syncFinished( SyncResult( SyncResult::Error ))); + SyncResult res( SyncResult::Error ); + res.setErrorString( tr("Sitecopy configuration problem, check $HOME/.sitecopyrc")); + incrementErrorCount(); + emit( syncFinished( res )); } - if( exitCode > 0 ) { + if( exitCode > 1 ) { // error has happened. QString out( _lastOutput ); SyncResult res( SyncResult::Error ); res.setErrorString( out ); qDebug() << "An error happened: " << out; + incrementErrorCount(); emit syncFinished( res ); return; } @@ -132,10 +136,7 @@ void SiteCopyFolder::slotFinished(int exitCode, QProcess::ExitStatus exitStatus) startSiteCopy( "--update", Finish ); // update from owncloud } else if( _NextStep == Finish ) { qDebug() << "Finished!"; - - emit syncFinished((exitCode == -1 ) ? - SyncResult(SyncResult::Error) - : SyncResult(SyncResult::Success)); + emit syncFinished( SyncResult(SyncResult::Success) ); // mLocalChangesSeen = false; } else if( _NextStep == Status ) { startSiteCopy( "--flatlist", DisplayStatus ); @@ -149,7 +150,7 @@ void SiteCopyFolder::slotFinished(int exitCode, QProcess::ExitStatus exitStatus) // No update needed emit syncFinished( SyncResult( SyncResult::Success ) ); } else { - qDebug() << "Got an invalid exit code " << exitCode; + qDebug() << "Got an unknown exit code " << exitCode; emit syncFinished( SyncResult( SyncResult::Error ) ); } } @@ -162,7 +163,7 @@ void SiteCopyFolder::analyzeStatus() QString out( _lastOutput ); qDebug() << "Output: " << out; - mChangesHash.clear(); + _ChangesHash.clear(); QStringList items; QString action; @@ -175,7 +176,7 @@ void SiteCopyFolder::analyzeStatus() } if( l.startsWith( "sectend|")) { action = l.mid(8); - mChangesHash.insert( action, items ); + _ChangesHash.insert( action, items ); items.clear(); } if( l.startsWith( "item|" )) { diff --git a/src/mirall/sitecopyfolder.h b/src/mirall/sitecopyfolder.h index 0e2370aea..085d286fc 100644 --- a/src/mirall/sitecopyfolder.h +++ b/src/mirall/sitecopyfolder.h @@ -62,11 +62,11 @@ private: QProcess *_SiteCopy; int _syncCount; - QByteArray _lastOutput; - QString _StatusString; + QByteArray _lastOutput; + QString _StatusString; SiteCopyState _NextStep; - QString _siteCopyAlias; - QHash mChangesHash; + QString _siteCopyAlias; + QHash _ChangesHash; };