From fd902e82f6352c28dfc88911aaac52a3e19cdc9d Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Thu, 26 Oct 2023 16:50:43 +0200 Subject: [PATCH] Add reason parameter to sync abort methods --- src/gui/accountsettings.cpp | 4 ++-- src/gui/folder.cpp | 7 ++++--- src/gui/folder.h | 2 +- src/gui/folderman.cpp | 4 ++-- src/gui/folderstatusmodel.cpp | 4 ++-- src/gui/owncloudgui.cpp | 2 +- src/libsync/syncengine.cpp | 6 +++--- src/libsync/syncengine.h | 4 ++-- test/testchunkingng.cpp | 6 +++--- test/testdownload.cpp | 5 ++++- test/testsyncengine.cpp | 2 +- 11 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp index f5aa2638417..9bba0023550 100644 --- a/src/gui/accountsettings.cpp +++ b/src/gui/accountsettings.cpp @@ -609,7 +609,7 @@ void AccountSettings::slotEnableCurrentFolder(bool terminate) // message box can return at any time while the thread keeps running, // so better check again after the user has responded. if (folder->isSyncRunning() && terminate) { - folder->slotTerminateSync(); + folder->slotTerminateSync(tr("Sync paused by user")); } folder->slotNextSyncFullLocalDiscovery(); // ensure we don't forget about local errors folder->setSyncPaused(!currentlyPaused); @@ -645,7 +645,7 @@ void AccountSettings::slotForceSyncCurrentFolder() // Terminate and reschedule any running sync for (auto *folder : FolderMan::instance()->folders()) { if (folder->isSyncRunning()) { - folder->slotTerminateSync(); + folder->slotTerminateSync(tr("User triggered force sync")); FolderMan::instance()->scheduler()->enqueueFolder(folder); } } diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp index fd475cd68cb..c619c92a8e5 100644 --- a/src/gui/folder.cpp +++ b/src/gui/folder.cpp @@ -806,7 +806,8 @@ void Folder::setVirtualFilesEnabled(bool enabled) }; if (isSyncRunning()) { connect(this, &Folder::syncFinished, this, finalizeVfsSwitch, Qt::SingleShotConnection); - slotTerminateSync(); + QString reason; + slotTerminateSync(tr("Switching VFS mode on folder '%1'").arg(displayName())); } else { finalizeVfsSwitch(); } @@ -879,12 +880,12 @@ bool Folder::isFileExcludedRelative(const QString &relativePath) const return isFileExcludedAbsolute(path() + relativePath); } -void Folder::slotTerminateSync() +void Folder::slotTerminateSync(const QString &reason) { if (isReady()) { qCInfo(lcFolder) << "folder " << path() << " Terminating!"; if (_engine->isSyncRunning()) { - _engine->abort(); + _engine->abort(reason); setSyncState(SyncResult::SyncAbortRequested); } } diff --git a/src/gui/folder.h b/src/gui/folder.h index b5ad8e321b4..1585fb79fd9 100644 --- a/src/gui/folder.h +++ b/src/gui/folder.h @@ -362,7 +362,7 @@ public slots: /** * terminate the current sync run */ - void slotTerminateSync(); + void slotTerminateSync(const QString &reason); // connected to the corresponding signals in the SyncEngine void slotAboutToRemoveAllFiles(SyncFileItem::Direction); diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp index d4d4ea941a7..fcc1217be4e 100644 --- a/src/gui/folderman.cpp +++ b/src/gui/folderman.cpp @@ -387,7 +387,7 @@ void FolderMan::slotIsConnectedChanged() if (f && f->isSyncRunning() && f->accountState() == accountState) { - f->slotTerminateSync(); + f->slotTerminateSync(tr("Account disconnected or paused")); } } } @@ -602,7 +602,7 @@ void FolderMan::removeFolder(Folder *f) const bool currentlyRunning = f->isSyncRunning(); if (currentlyRunning) { // abort the sync now - f->slotTerminateSync(); + f->slotTerminateSync(tr("Folder is about to be removed")); } f->setSyncPaused(true); diff --git a/src/gui/folderstatusmodel.cpp b/src/gui/folderstatusmodel.cpp index ad1e76ed4b3..d598c167d2c 100644 --- a/src/gui/folderstatusmodel.cpp +++ b/src/gui/folderstatusmodel.cpp @@ -938,7 +938,7 @@ void FolderStatusModel::slotApplySelectiveSync() const auto changes = (oldBlackListSet - blackListSet) + (blackListSet - oldBlackListSet); if (!changes.isEmpty()) { if (folder->isSyncRunning()) { - folder->slotTerminateSync(); + folder->slotTerminateSync(tr("Selective sync list changed")); } //The part that changed should not be read from the DB on next sync because there might be new folders // (the ones that are no longer in the blacklist) @@ -1219,7 +1219,7 @@ void FolderStatusModel::slotSyncAllPendingBigFolders() // Trigger a sync if (folder->isSyncRunning()) { - folder->slotTerminateSync(); + folder->slotTerminateSync(tr("User triggered sync-all for selective synced folder")); } // The part that changed should not be read from the DB on next sync because there might be new folders // (the ones that are no longer in the blacklist) diff --git a/src/gui/owncloudgui.cpp b/src/gui/owncloudgui.cpp index c289a5762e4..577d188a13b 100644 --- a/src/gui/owncloudgui.cpp +++ b/src/gui/owncloudgui.cpp @@ -943,7 +943,7 @@ void ownCloudGui::setPauseOnAllFoldersHelper(const QList &accou if (accounts.contains(f->accountState())) { f->setSyncPaused(pause); if (pause) { - f->slotTerminateSync(); + f->slotTerminateSync(tr("User paused sync for account '%1'").arg(f->accountState()->account()->displayName())); } } } diff --git a/src/libsync/syncengine.cpp b/src/libsync/syncengine.cpp index a8fd2a2f8fa..185b2e6b1ae 100644 --- a/src/libsync/syncengine.cpp +++ b/src/libsync/syncengine.cpp @@ -84,7 +84,7 @@ SyncEngine::SyncEngine(AccountPtr account, const QUrl &baseUrl, const QString &l SyncEngine::~SyncEngine() { _goingDown = true; - abort(); + abort(tr("application exit", "abort reason")); _excludedFiles.reset(); } @@ -855,7 +855,7 @@ bool SyncEngine::shouldDiscoverLocally(const QString &path) const return false; } -void SyncEngine::abort() +void SyncEngine::abort(const QString &reason) { bool aborting = false; if (_propagator) { @@ -871,7 +871,7 @@ void SyncEngine::abort() if (aborting) { qCInfo(lcEngine) << "Aborting sync"; if (!_goingDown) { - Q_EMIT syncError(tr("Aborted")); + Q_EMIT syncError(tr("Aborted due to %1").arg(reason)); } finalize(false); } diff --git a/src/libsync/syncengine.h b/src/libsync/syncengine.h index 8834d7a38dd..582499a79fa 100644 --- a/src/libsync/syncengine.h +++ b/src/libsync/syncengine.h @@ -72,8 +72,8 @@ class OWNCLOUDSYNC_EXPORT SyncEngine : public QObject Q_INVOKABLE void startSync(); void setNetworkLimits(int upload, int download); - /* Abort the sync. Called from the main thread */ - void abort(); + /* Abort the sync. Called from the main thread */ + void abort(const QString &reason); bool isSyncRunning() const { return _syncRunning; } diff --git a/test/testchunkingng.cpp b/test/testchunkingng.cpp index 9cf8b5ad108..77deebcbd24 100644 --- a/test/testchunkingng.cpp +++ b/test/testchunkingng.cpp @@ -34,7 +34,7 @@ void partialUpload(FakeFolder &fakeFolder, const QString &name, quint64 size) [&](const ProgressInfo &progress) { if (progress.completedSize() > (progress.totalSize() /3 )) { sizeWhenAbort = progress.completedSize(); - fakeFolder.syncEngine().abort(); + fakeFolder.syncEngine().abort({}); } }); @@ -248,7 +248,7 @@ private slots: const auto responseDelay = 24h; // bigger than abort-wait timeout fakeFolder.setServerOverride([&](QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice *) -> QNetworkReply * { if (request.attribute(QNetworkRequest::CustomVerbAttribute).toByteArray() == "MOVE") { - QTimer::singleShot(50ms, &parent, [&]() { fakeFolder.syncEngine().abort(); }); + QTimer::singleShot(50ms, &parent, [&]() { fakeFolder.syncEngine().abort({}); }); moveChecksumHeader = request.rawHeader("OC-Checksum"); return new DelayedReply(responseDelay, fakeFolder.uploadState(), fakeFolder.remoteModifier(), op, request, &parent); } else if (op == QNetworkAccessManager::GetOperation) { @@ -345,7 +345,7 @@ private slots: const auto responseDelay = 200ms; // smaller than abort-wait timeout fakeFolder.setServerOverride([&](QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice *) -> QNetworkReply * { if (request.attribute(QNetworkRequest::CustomVerbAttribute).toByteArray() == "MOVE") { - QTimer::singleShot(50ms, &parent, [&]() { fakeFolder.syncEngine().abort(); }); + QTimer::singleShot(50ms, &parent, [&]() { fakeFolder.syncEngine().abort({}); }); // while the response is delayed, the move is performed in the constructor, thus it happens immediately return new DelayedReply(responseDelay, fakeFolder.uploadState(), fakeFolder.remoteModifier(), op, request, &parent); } diff --git a/test/testdownload.cpp b/test/testdownload.cpp index f22369b3dd5..d46c1fcd7f0 100644 --- a/test/testdownload.cpp +++ b/test/testdownload.cpp @@ -214,7 +214,10 @@ private slots: }); bool timedOut = false; - QTimer::singleShot(10s, &fakeFolder.syncEngine(), [&]() { timedOut = true; fakeFolder.syncEngine().abort(); }); + QTimer::singleShot(10s, &fakeFolder.syncEngine(), [&]() { + timedOut = true; + fakeFolder.syncEngine().abort({}); + }); if (filesAreDehydrated) { QVERIFY(fakeFolder.applyLocalModificationsAndSync()); // Success, because files are never downloaded } else { diff --git a/test/testsyncengine.cpp b/test/testsyncengine.cpp index 369f6c6d020..0c7201df173 100644 --- a/test/testsyncengine.cpp +++ b/test/testsyncengine.cpp @@ -779,7 +779,7 @@ private slots: // wait until the sync engine is ready // wait a second and abort connect(&fakeFolder.syncEngine(), &SyncEngine::aboutToPropagate, &fakeFolder.syncEngine(), - [&]() { QTimer::singleShot(1s, &fakeFolder.syncEngine(), [&]() { fakeFolder.syncEngine().abort(); }); }); + [&]() { QTimer::singleShot(1s, &fakeFolder.syncEngine(), [&]() { fakeFolder.syncEngine().abort({}); }); }); QVERIFY(!fakeFolder.applyLocalModificationsAndSync()); QCOMPARE(counter->nPUT, 3);