1
0
mirror of https://github.com/chylex/Nextcloud-Desktop.git synced 2025-05-08 11:34:08 +02:00

FolderMan: Remove assumption of unique running sync

This commit is contained in:
Christian Kamm 2020-11-26 17:19:20 +01:00 committed by Kevin Ottens
parent 22e08cf6ad
commit c3b1a872aa
No known key found for this signature in database
GPG Key ID: 074BBBCB8DECC9E2
7 changed files with 82 additions and 49 deletions

View File

@ -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

View File

@ -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;

View File

@ -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
*/

View File

@ -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<Folder *> 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<Folder *>(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 &)
{
auto f = qobject_cast<Folder *>(sender());
ASSERT(f);
if (!f)
return;
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()));
qPrintable(f->shortGuiLocalPath()),
qPrintable(f->accountState()->account()->displayName()),
qPrintable(f->remoteUrl().toString()));
_lastSyncFolder = _currentSyncFolder;
_currentSyncFolder = nullptr;
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) {

View File

@ -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.

View File

@ -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) {

View File

@ -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);
};