From: Christian Kamm Date: Thu, 26 Nov 2020 16:19:20 +0000 (+0100) Subject: FolderMan: Remove assumption of unique running sync X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~21^2~468^2~410 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=c3b1a872aa22b002d41f8af9eb08cb164df813d8;p=nextcloud-desktop.git FolderMan: Remove assumption of unique running sync --- diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp index e7d77e4b1..9f06e2d62 100644 --- a/src/gui/accountsettings.cpp +++ b/src/gui/accountsettings.cpp @@ -426,7 +426,7 @@ void AccountSettings::slotCustomContextMenuRequested(const QPoint &pos) if (!folderPaused) { ac = menu->addAction(tr("Force sync now")); - if (folderMan->currentSyncFolder() == folder) { + if (folder && folder->isSyncRunning()) { ac->setText(tr("Restart sync")); } ac->setEnabled(folderConnected); @@ -738,9 +738,11 @@ void AccountSettings::slotForceSyncCurrentFolder() FolderMan *folderMan = FolderMan::instance(); if (auto selectedFolder = folderMan->folder(selectedFolderAlias())) { // Terminate and reschedule any running sync - if (Folder *current = folderMan->currentSyncFolder()) { - folderMan->terminateSyncProcess(); - folderMan->scheduleFolder(current); + for (auto f : folderMan->map()) { + if (f->isSyncRunning()) { + f->slotTerminateSync(); + folderMan->scheduleFolder(f); + } } selectedFolder->slotWipeErrorBlacklist(); // issue #6757 diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp index ebe9feb91..6951c9b11 100644 --- a/src/gui/folder.cpp +++ b/src/gui/folder.cpp @@ -221,6 +221,11 @@ bool Folder::isBusy() const return _engine->isSyncRunning(); } +bool Folder::isSyncRunning() const +{ + return _engine->isSyncRunning(); +} + QString Folder::remotePath() const { return _definition.targetPath; diff --git a/src/gui/folder.h b/src/gui/folder.h index 8d4ab1915..a5b0641c9 100644 --- a/src/gui/folder.h +++ b/src/gui/folder.h @@ -164,6 +164,9 @@ public: */ virtual bool isBusy() const; + /** True if the folder is currently synchronizing */ + bool isSyncRunning() const; + /** * return the last sync result with error message and status */ diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp index 5a3a5fbf6..63e971c0f 100644 --- a/src/gui/folderman.cpp +++ b/src/gui/folderman.cpp @@ -541,19 +541,6 @@ void FolderMan::slotFolderCanSyncChanged() } } -// this really terminates the current sync process -// ie. no questions, no prisoners -// csync still remains in a stable state, regardless of that. -void FolderMan::terminateSyncProcess() -{ - Folder *f = _currentSyncFolder; - if (f) { - // This will, indirectly and eventually, call slotFolderSyncFinished - // and thereby clear _currentSyncFolder. - f->slotTerminateSync(); - } -} - Folder *FolderMan::folder(const QString &alias) { if (!alias.isEmpty()) { @@ -665,7 +652,7 @@ void FolderMan::slotRunOneEtagJob() //qCDebug(lcFolderMan) << "No more remote ETag check jobs to schedule."; /* now it might be a good time to check for restarting... */ - if (!_currentSyncFolder && _appRestartRequired) { + if (!isAnySyncRunning() && _appRestartRequired) { restartApplication(); } } else { @@ -697,9 +684,12 @@ void FolderMan::slotAccountStateChanged() qCInfo(lcFolderMan) << "Account" << accountName << "disconnected or paused, " "terminating or descheduling sync folders"; - if (_currentSyncFolder - && _currentSyncFolder->accountState() == accountState) { - _currentSyncFolder->slotTerminateSync(); + foreach (Folder *f, _folderMap.values()) { + if (f + && f->isSyncRunning() + && f->accountState() == accountState) { + f->slotTerminateSync(); + } } QMutableListIterator it(_scheduledFolders); @@ -734,7 +724,7 @@ void FolderMan::startScheduledSyncSoon() if (_scheduledFolders.empty()) { return; } - if (_currentSyncFolder) { + if (isAnySyncRunning()) { return; } @@ -772,8 +762,11 @@ void FolderMan::startScheduledSyncSoon() */ void FolderMan::slotStartScheduledFolderSync() { - if (_currentSyncFolder) { - qCInfo(lcFolderMan) << "Currently folder " << _currentSyncFolder->remoteUrl().toString() << " is running, wait for finish!"; + if (isAnySyncRunning()) { + for (auto f : _folderMap) { + if (f->isSyncRunning()) + qCInfo(lcFolderMan) << "Currently folder " << f->remoteUrl().toString() << " is running, wait for finish!"; + } return; } @@ -820,7 +813,7 @@ void FolderMan::slotEtagPollTimerTimeout() if (!f) { continue; } - if (_currentSyncFolder == f) { + if (f->isSyncRunning()) { continue; } if (_scheduledFolders.contains(f)) { @@ -931,12 +924,29 @@ void FolderMan::slotScheduleFolderByTime() } } +bool FolderMan::isAnySyncRunning() const +{ + if (_currentSyncFolder) + return true; + + for (auto f : _folderMap) { + if (f->isSyncRunning()) + return true; + } + return false; +} + void FolderMan::slotFolderSyncStarted() { + auto f = qobject_cast(sender()); + ASSERT(f); + if (!f) + return; + qCInfo(lcFolderMan, ">========== Sync started for folder [%s] of account [%s] with remote [%s]", - qPrintable(_currentSyncFolder->shortGuiLocalPath()), - qPrintable(_currentSyncFolder->accountState()->account()->displayName()), - qPrintable(_currentSyncFolder->remoteUrl().toString())); + qPrintable(f->shortGuiLocalPath()), + qPrintable(f->accountState()->account()->displayName()), + qPrintable(f->remoteUrl().toString())); } /* @@ -947,15 +957,22 @@ void FolderMan::slotFolderSyncStarted() */ void FolderMan::slotFolderSyncFinished(const SyncResult &) { - qCInfo(lcFolderMan, "<========== Sync finished for folder [%s] of account [%s] with remote [%s]", - qPrintable(_currentSyncFolder->shortGuiLocalPath()), - qPrintable(_currentSyncFolder->accountState()->account()->displayName()), - qPrintable(_currentSyncFolder->remoteUrl().toString())); + auto f = qobject_cast(sender()); + ASSERT(f); + if (!f) + return; - _lastSyncFolder = _currentSyncFolder; - _currentSyncFolder = nullptr; + qCInfo(lcFolderMan, "<========== Sync finished for folder [%s] of account [%s] with remote [%s]", + qPrintable(f->shortGuiLocalPath()), + qPrintable(f->accountState()->account()->displayName()), + qPrintable(f->remoteUrl().toString())); - startScheduledSyncSoon(); + if (f == _currentSyncFolder) { + _lastSyncFolder = _currentSyncFolder; + _currentSyncFolder = nullptr; + } + if (!isAnySyncRunning()) + startScheduledSyncSoon(); } Folder *FolderMan::addFolder(AccountState *accountState, const FolderDefinition &folderDefinition) @@ -1074,10 +1091,10 @@ void FolderMan::removeFolder(Folder *f) qCInfo(lcFolderMan) << "Removing " << f->alias(); - const bool currentlyRunning = (_currentSyncFolder == f); + const bool currentlyRunning = f->isSyncRunning(); if (currentlyRunning) { // abort the sync now - terminateSyncProcess(); + f->slotTerminateSync(); } if (_scheduledFolders.removeAll(f) > 0) { @@ -1202,7 +1219,7 @@ void FolderMan::slotWipeFolderForAccount(AccountState *accountState) const bool currentlyRunning = (_currentSyncFolder == f); if (currentlyRunning) { // abort the sync now - terminateSyncProcess(); + _currentSyncFolder->slotTerminateSync(); } if (_scheduledFolders.removeAll(f) > 0) { diff --git a/src/gui/folderman.h b/src/gui/folderman.h index 057edd625..e083d158f 100644 --- a/src/gui/folderman.h +++ b/src/gui/folderman.h @@ -164,9 +164,22 @@ public: /** * Access to the currently syncing folder. + * + * Note: This is only the folder that's currently syncing *as-scheduled*. There + * may be externally-managed syncs such as from placeholder hydrations. + * + * See also isAnySyncRunning() */ Folder *currentSyncFolder() const; + /** + * Returns true if any folder is currently syncing. + * + * This might be a FolderMan-scheduled sync, or a externally + * managed sync like a placeholder hydration. + */ + bool isAnySyncRunning() const; + /** Removes all folders */ int unloadAndDeleteAllFolders(); @@ -188,13 +201,6 @@ public: void setDirtyProxy(); void setDirtyNetworkLimits(); - /** - * Terminates the current folder sync. - * - * It does not switch the folder to paused state. - */ - void terminateSyncProcess(); - signals: /** * signal to indicate a folder has changed its sync state. diff --git a/src/gui/folderstatusmodel.cpp b/src/gui/folderstatusmodel.cpp index 73d68fc96..dff804e3a 100644 --- a/src/gui/folderstatusmodel.cpp +++ b/src/gui/folderstatusmodel.cpp @@ -1090,9 +1090,9 @@ void FolderStatusModel::slotFolderSyncStateChange(Folder *f) } else if (state == SyncResult::NotYetStarted) { FolderMan *folderMan = FolderMan::instance(); int pos = folderMan->scheduleQueue().indexOf(f); - if (folderMan->currentSyncFolder() - && folderMan->currentSyncFolder() != f) { - pos += 1; + for (auto other : folderMan->map()) { + if (other != f && other->isSyncRunning()) + pos += 1; } QString message; if (pos <= 0) { diff --git a/src/gui/owncloudgui.cpp b/src/gui/owncloudgui.cpp index 0fd1abf4b..aec990e79 100644 --- a/src/gui/owncloudgui.cpp +++ b/src/gui/owncloudgui.cpp @@ -245,7 +245,7 @@ void ownCloudGui::slotComputeOverallSyncStatus() // FIXME: So this doesn't do anything? Needs to be revisited Q_UNUSED(text) // Don't overwrite the status if we're currently syncing - if (FolderMan::instance()->currentSyncFolder()) + if (FolderMan::instance()->isAnySyncRunning()) return; //_actionStatus->setText(text); };