Skip to content

Commit 3ed0150

Browse files
committed
Ensure syncStateChanged is emitted
Fixes: #9270
1 parent fae88c3 commit 3ed0150

File tree

4 files changed

+34
-58
lines changed

4 files changed

+34
-58
lines changed

changelog/unreleased/9270

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
Bugfix: Fix computation of sync status when multiple folders are synced
22

33
https://github.com/owncloud/client/issues/9270
4+
https://github.com/owncloud/client/pull/10536
5+
https://github.com/owncloud/client/pull/10642

src/gui/folder.cpp

+26-32
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ Folder::Folder(const FolderDefinition &definition,
109109
if (definition.paused) {
110110
status = SyncResult::Paused;
111111
}
112-
_syncResult.setStatus(status);
113-
112+
setSyncState(status);
114113
// check if the local path exists
115114
if (checkLocalPath()) {
116115
prepareFolder(path());
@@ -261,7 +260,7 @@ bool Folder::checkLocalPath()
261260
if (!error.isEmpty()) {
262261
qCWarning(lcFolder) << error;
263262
_syncResult.appendErrorString(error);
264-
_syncResult.setStatus(SyncResult::SetupError);
263+
setSyncState(SyncResult::SetupError);
265264
return false;
266265
}
267266
return true;
@@ -454,19 +453,21 @@ void Folder::setSyncPaused(bool paused)
454453
_definition.paused = paused;
455454
saveToSettings();
456455

456+
emit syncPausedChanged(this, paused);
457457
if (!paused) {
458458
setSyncState(SyncResult::NotYetStarted);
459459
} else {
460460
setSyncState(SyncResult::Paused);
461461
}
462-
emit syncPausedChanged(this, paused);
463-
emit syncStateChange();
464462
emit canSyncChanged();
465463
}
466464

467465
void Folder::setSyncState(SyncResult::Status state)
468466
{
469-
_syncResult.setStatus(state);
467+
if (state != _syncResult.status()) {
468+
_syncResult.setStatus(state);
469+
Q_EMIT syncStateChange();
470+
}
470471
}
471472

472473
SyncResult Folder::syncResult() const
@@ -477,7 +478,7 @@ SyncResult Folder::syncResult() const
477478
void Folder::prepareToSync()
478479
{
479480
_syncResult.reset();
480-
_syncResult.setStatus(SyncResult::NotYetStarted);
481+
setSyncState(SyncResult::NotYetStarted);
481482
}
482483

483484
void Folder::slotRunEtagJob()
@@ -629,7 +630,7 @@ void Folder::startVfs()
629630
const auto result = Vfs::checkAvailability(path(), _vfs->mode());
630631
if (!result) {
631632
_syncResult.appendErrorString(result.error());
632-
_syncResult.setStatus(SyncResult::SetupError);
633+
setSyncState(SyncResult::SetupError);
633634
return;
634635
}
635636

@@ -658,7 +659,7 @@ void Folder::startVfs()
658659
});
659660
connect(_vfs.data(), &Vfs::error, this, [this](const QString &error) {
660661
_syncResult.appendErrorString(error);
661-
_syncResult.setStatus(SyncResult::SetupError);
662+
setSyncState(SyncResult::SetupError);
662663
_vfsIsReady = false;
663664
});
664665

@@ -993,8 +994,7 @@ void Folder::startSync()
993994
}
994995

995996
_timeSinceLastSyncStart.start();
996-
_syncResult.setStatus(SyncResult::SyncPrepare);
997-
emit syncStateChange();
997+
setSyncState(SyncResult::SyncPrepare);
998998

999999
qCInfo(lcFolder) << "*** Start syncing " << remoteUrl().toString() << "client version"
10001000
<< Theme::instance()->aboutVersions(Theme::VersionFormat::OneLiner);
@@ -1074,8 +1074,7 @@ void Folder::slotSyncError(const QString &message, ErrorCategory category)
10741074
void Folder::slotSyncStarted()
10751075
{
10761076
qCInfo(lcFolder) << "#### Propagation start ####################################################";
1077-
_syncResult.setStatus(SyncResult::SyncRunning);
1078-
emit syncStateChange();
1077+
setSyncState(SyncResult::SyncRunning);
10791078
}
10801079

10811080
void Folder::slotSyncFinished(bool success)
@@ -1097,49 +1096,44 @@ void Folder::slotSyncFinished(bool success)
10971096

10981097
auto anotherSyncNeeded = _engine->isAnotherSyncNeeded();
10991098

1099+
auto syncStatus = SyncResult::Status::Undefined;
1100+
11001101
if (syncError) {
1101-
_syncResult.setStatus(SyncResult::Error);
1102+
syncStatus = SyncResult::Error;
11021103
} else if (_syncResult.foundFilesNotSynced()) {
1103-
_syncResult.setStatus(SyncResult::Problem);
1104+
syncStatus = SyncResult::Problem;
11041105
} else if (_definition.paused) {
11051106
// Maybe the sync was terminated because the user paused the folder
1106-
_syncResult.setStatus(SyncResult::Paused);
1107+
syncStatus = SyncResult::Paused;
11071108
} else {
1108-
_syncResult.setStatus(SyncResult::Success);
1109+
syncStatus = SyncResult::Success;
11091110
}
11101111

11111112
// Count the number of syncs that have failed in a row.
1112-
if (_syncResult.status() == SyncResult::Success
1113-
|| _syncResult.status() == SyncResult::Problem) {
1113+
if (syncStatus == SyncResult::Success || syncStatus == SyncResult::Problem) {
11141114
_consecutiveFailingSyncs = 0;
11151115
} else {
11161116
_consecutiveFailingSyncs++;
11171117
qCInfo(lcFolder) << "the last" << _consecutiveFailingSyncs << "syncs failed";
11181118
}
11191119

1120-
if (_syncResult.status() == SyncResult::Success && success) {
1120+
if (syncStatus == SyncResult::Success && success) {
11211121
// Clear the white list as all the folders that should be on that list are sync-ed
11221122
journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncWhiteList, QStringList());
11231123
}
11241124

1125-
if ((_syncResult.status() == SyncResult::Success
1126-
|| _syncResult.status() == SyncResult::Problem)
1127-
&& success) {
1125+
if ((syncStatus == SyncResult::Success || syncStatus == SyncResult::Problem) && success) {
11281126
if (_engine->lastLocalDiscoveryStyle() == LocalDiscoveryStyle::FilesystemOnly) {
11291127
_timeSinceLastFullLocalDiscovery.start();
11301128
}
11311129
}
11321130

1131+
if (syncStatus != SyncResult::Undefined) {
1132+
setSyncState(syncStatus);
1133+
}
11331134

1134-
emit syncStateChange();
1135-
1136-
// The syncFinished result that is to be triggered here makes the folderman
1137-
// clear the current running sync folder marker.
1138-
// Lets wait a bit to do that because, as long as this marker is not cleared,
1139-
// file system change notifications are ignored for that folder. And it takes
1140-
// some time under certain conditions to make the file system notifications
1141-
// all come in.
1142-
QTimer::singleShot(200ms, this, &Folder::slotEmitFinishedDelayed);
1135+
// syncStateChange from setSyncState needs to be emitted first
1136+
QTimer::singleShot(0, this, &Folder::slotEmitFinishedDelayed);
11431137

11441138
_lastSyncDuration = std::chrono::milliseconds(_timeSinceLastSyncStart.elapsed());
11451139
_timeSinceLastSyncDone.start();

src/gui/folderman.cpp

+6-22
Original file line numberDiff line numberDiff line change
@@ -172,20 +172,11 @@ void FolderMan::unloadFolder(Folder *f)
172172

173173

174174
if (!f->hasSetupError()) {
175-
disconnect(f, &Folder::syncStarted,
176-
this, &FolderMan::slotFolderSyncStarted);
177-
disconnect(f, &Folder::syncFinished,
178-
this, &FolderMan::slotFolderSyncFinished);
179-
disconnect(f, &Folder::syncStateChange,
180-
this, &FolderMan::slotForwardFolderSyncStateChange);
181-
disconnect(f, &Folder::syncPausedChanged,
182-
this, &FolderMan::slotFolderSyncPaused);
183-
disconnect(&f->syncEngine().syncFileStatusTracker(), &SyncFileStatusTracker::fileStatusChanged,
184-
_socketApi.data(), &SocketApi::broadcastStatusPushMessage);
185-
disconnect(f, &Folder::watchedFileChangedExternally,
186-
&f->syncEngine().syncFileStatusTracker(), &SyncFileStatusTracker::slotPathTouched);
187-
188-
f->syncEngine().disconnect(f);
175+
disconnect(f, nullptr, this, nullptr);
176+
disconnect(f, nullptr, &f->syncEngine().syncFileStatusTracker(), nullptr);
177+
disconnect(&f->syncEngine(), nullptr, f, nullptr);
178+
disconnect(
179+
&f->syncEngine().syncFileStatusTracker(), &SyncFileStatusTracker::fileStatusChanged, _socketApi.data(), &SocketApi::broadcastStatusPushMessage);
189180
}
190181
}
191182

@@ -723,13 +714,6 @@ void FolderMan::slotRemoveFoldersForAccount(const AccountStatePtr &accountState)
723714
}
724715
}
725716

726-
void FolderMan::slotForwardFolderSyncStateChange()
727-
{
728-
if (Folder *f = qobject_cast<Folder *>(sender())) {
729-
emit folderSyncStateChange(f);
730-
}
731-
}
732-
733717
void FolderMan::slotServerVersionChanged(Account *account)
734718
{
735719
// Pause folders if the server version is unsupported
@@ -906,7 +890,7 @@ Folder *FolderMan::addFolderInternal(
906890
if (!folder->hasSetupError()) {
907891
connect(folder, &Folder::syncStarted, this, &FolderMan::slotFolderSyncStarted);
908892
connect(folder, &Folder::syncFinished, this, &FolderMan::slotFolderSyncFinished);
909-
connect(folder, &Folder::syncStateChange, this, &FolderMan::slotForwardFolderSyncStateChange);
893+
connect(folder, &Folder::syncStateChange, this, [folder, this] { Q_EMIT folderSyncStateChange(folder); });
910894
connect(folder, &Folder::syncPausedChanged, this, &FolderMan::slotFolderSyncPaused);
911895
connect(folder, &Folder::canSyncChanged, this, &FolderMan::slotFolderCanSyncChanged);
912896
connect(&folder->syncEngine().syncFileStatusTracker(), &SyncFileStatusTracker::fileStatusChanged,

src/gui/folderman.h

-4
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,6 @@ private slots:
314314

315315
void slotRemoveFoldersForAccount(const AccountStatePtr &accountState);
316316

317-
// Wraps the Folder::syncStateChange() signal into the
318-
// FolderMan::folderSyncStateChange(Folder*) signal.
319-
void slotForwardFolderSyncStateChange();
320-
321317
void slotServerVersionChanged(Account *account);
322318

323319
/**

0 commit comments

Comments
 (0)