Skip to content

Commit

Permalink
Add reason parameter to sync abort methods
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjv committed Jan 4, 2024
1 parent 140276d commit fd902e8
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/gui/accountsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/gui/folder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/folder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/gui/folderman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ void FolderMan::slotIsConnectedChanged()
if (f
&& f->isSyncRunning()
&& f->accountState() == accountState) {
f->slotTerminateSync();
f->slotTerminateSync(tr("Account disconnected or paused"));
}
}
}
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/gui/folderstatusmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/gui/owncloudgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ void ownCloudGui::setPauseOnAllFoldersHelper(const QList<AccountStatePtr> &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()));
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/libsync/syncengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/libsync/syncengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down
6 changes: 3 additions & 3 deletions test/testchunkingng.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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({});
}
});

Expand Down Expand Up @@ -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<FakeChunkMoveReply>(responseDelay, fakeFolder.uploadState(), fakeFolder.remoteModifier(), op, request, &parent);
} else if (op == QNetworkAccessManager::GetOperation) {
Expand Down Expand Up @@ -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<FakeChunkMoveReply>(responseDelay, fakeFolder.uploadState(), fakeFolder.remoteModifier(), op, request, &parent);
}
Expand Down
5 changes: 4 additions & 1 deletion test/testdownload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion test/testsyncengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit fd902e8

Please sign in to comment.