Restart the sync when we detect we need to redo a sync

Fixes #1968
Relates #2038

(cherry picked from commit a84b7dc27e)

Conflicts:
	src/mirall/owncloudpropagator.h
	src/mirall/propagator_qnam.cpp
	src/mirall/syncengine.h
This commit is contained in:
Olivier Goffart 2014-09-10 17:25:13 +02:00
parent 1cd5681967
commit 9ae4d45243
6 changed files with 33 additions and 5 deletions

View file

@ -266,6 +266,7 @@ void Folder::slotPollTimerTimeout()
qDebug() << "* Polling" << alias() << "for changes. (time since last sync:" << (_timeSinceLastSync.elapsed() / 1000) << "s)";
if (quint64(_timeSinceLastSync.elapsed()) > MirallConfigFile().forceSyncInterval() ||
_lastEtag.isNull() ||
!(_syncResult.status() == SyncResult::Success ||_syncResult.status() == SyncResult::Problem)) {
qDebug() << "** Force Sync now, state is " << _syncResult.statusString();
emit scheduleToSync(alias());
@ -659,10 +660,13 @@ void Folder::slotSyncFinished()
bubbleUpSyncResult();
_engine.reset(0);
bool anotherSyncNeeded = false;
if (_engine) {
anotherSyncNeeded = _engine->isAnotherSyncNeeded();
_engine.reset(0);
}
// _watcher->setEventsEnabledDelayed(2000);
_pollTimer.start();
_timeSinceLastSync.restart();
if (_csyncError) {
@ -689,6 +693,16 @@ void Folder::slotSyncFinished()
// all come in.
QTimer::singleShot(200, this, SLOT(slotEmitFinishedDelayed() ));
if (!anotherSyncNeeded) {
_pollTimer.start();
_timeSinceLastSync.restart();
} else {
// Another sync is required. We will make sure that the poll timer occurs soon enough
// and we clear the etag to force a sync
_lastEtag.clear();
QTimer::singleShot(1000, this, SLOT(slotPollTimerTimeout() ));
}
}
void Folder::slotEmitFinishedDelayed()

View file

@ -144,6 +144,7 @@ bool PropagateItemJob::checkForProblemsWithShared(int httpStatusCode, const QStr
// Also remove the inodes and fileid from the db so no further renames are tried for
// this item.
_propagator->_journal->avoidRenamesOnNextSync(_item._file);
_propagator->_anotherSyncNeeded = true;
}
if( newJob ) {
newJob->setRestoreJobMsg(msg);

View file

@ -209,6 +209,7 @@ public:
, _journal(progressDb)
, _finishedEmited(false)
, _activeJobs(0)
, _anotherSyncNeeded(false)
{ }
void start(const SyncFileItemVector &_syncedItems);
@ -221,6 +222,9 @@ public:
/* The number of currently active jobs */
int _activeJobs;
/** We detected that another sync is required after this one */
bool _anotherSyncNeeded;
/* The maximum number of active job in parallel */
int maximumActiveJob();

View file

@ -422,6 +422,7 @@ void PropagateUploadFileQNAM::slotPutFinished()
if (Utility::qDateTimeToTime_t(fi.lastModified()) != _item._modtime) {
qDebug() << "The local file has changed during upload:" << _item._modtime << "!=" << Utility::qDateTimeToTime_t(fi.lastModified()) << fi.lastModified();
_finished = true;
_propagator->_anotherSyncNeeded = true;
done(SyncFileItem::SoftError, tr("Local file changed during sync."));
// FIXME: the legacy code was retrying for a few seconds.
// and also checking that after the last chunk, and removed the file in case of INSTRUCTION_NEW

View file

@ -66,6 +66,7 @@ SyncEngine::SyncEngine(CSYNC *ctx, const QString& localPath, const QString& remo
, _hasRemoveFile(false)
, _uploadLimit(0)
, _downloadLimit(0)
, _anotherSyncNeeded(false)
{
qRegisterMetaType<SyncFileItem>("SyncFileItem");
qRegisterMetaType<SyncFileItem::Status>("SyncFileItem::Status");
@ -727,6 +728,8 @@ void SyncEngine::slotJobCompleted(const SyncFileItem &item)
void SyncEngine::slotFinished()
{
_anotherSyncNeeded = _anotherSyncNeeded || _propagator->_anotherSyncNeeded;
// emit the treewalk results.
if( ! _journal->postSyncCleanup( _seenFiles ) ) {
qDebug() << "Cleaning of synced ";
@ -938,6 +941,7 @@ void SyncEngine::checkForPermission()
// At this point we would need to go back to the propagate phase on both remote to take
// the decision.
_journal->avoidRenamesOnNextSync(it->_file);
_anotherSyncNeeded = true;
if (it->_isDirectory) {

View file

@ -63,6 +63,9 @@ public:
Utility::StopWatch &stopWatch() { return _stopWatch; }
/* Return true if we detected that another sync is needed to complete the sync */
bool isAnotherSyncNeeded() { return _anotherSyncNeeded; }
signals:
void csyncError( const QString& );
void csyncUnavailable();
@ -145,8 +148,9 @@ private:
// hash containing the permissions on the remote directory
QHash<QString, QByteArray> _remotePerms;
};
bool _anotherSyncNeeded;
};
class UpdateJob : public QObject {
Q_OBJECT
@ -163,7 +167,7 @@ class UpdateJob : public QObject {
}
public:
explicit UpdateJob(CSYNC *ctx, QObject* parent = 0)
: QObject(parent), _csync_ctx(ctx) {
: QObject(parent), _csync_ctx(ctx) {
// We need to forward the log property as csync uses thread local
// and updates run in another thread
_log_callback = csync_get_log_callback();