From 1ae01a575420aa72d1319c50ce7b94f4ed19203b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= <323649642+oc-tmueller@users.noreply.github.com> Date: Thu, 3 Dec 2026 15:02:03 +0100 Subject: [PATCH 1/4] fix: sync folders whose space arrives after the account connected A folder restored from the config stays unavailable until the spaces manager has loaded its space. If the account connects before the drives reply arrives, scheduling on connect skips the folder, and setting it available later did not enqueue it. Nothing else triggers a sync, so local changes made while the client was not running stayed unsynced until something changed on the server or on disk. Enqueue the folder in onSpacesAdded once it can sync. Co-Authored-By: Claude Opus 5.5 --- src/gui/folderman.cpp | 7 +++- test/testfolderman.cpp | 80 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 85 insertions(+), 2 deletions(-) diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp index 88db4858da0..f5146f6e559 100644 --- a/src/gui/folderman.cpp +++ b/src/gui/folderman.cpp @@ -442,7 +442,12 @@ void FolderMan::onSpacesAdded(const QUuid &accountId, QList s newUnsyncedSpaces.remove(space); else if (_folders.contains(accountId) && _folders[accountId].contains(space->id())) { newUnsyncedSpaces.remove(space); - _folders[accountId][space->id()]->setAvailable(true); + Folder *folder = _folders[accountId][space->id()]; + folder->setAvailable(true); + // a folder restored from the config was skipped when the account connected because its space was not known yet + if (folder->canSync()) { + _scheduler->enqueueFolder(folder); + } } } diff --git a/test/testfolderman.cpp b/test/testfolderman.cpp index 0576f49cd65..1745a609694 100644 --- a/test/testfolderman.cpp +++ b/test/testfolderman.cpp @@ -9,9 +9,12 @@ #include #include +#include "accountmanager.h" +#include "accountstate.h" #include "common/utility.h" +#include "connectionvalidator.h" #include "folderman.h" -#include "accountstate.h" +#include "graphapi/spacesmanager.h" #include "guiutility.h" #include "testutils/testutils.h" @@ -285,6 +288,81 @@ private Q_SLOTS: QVERIFY(folderman->checkPathValidity(dirPath + QStringLiteral("/OurSpacesSyncRoot/OurSpacesFolder"), FolderMan::NewFolderType::SpacesFolder, ourUuid) .isNull()); } + + /* + * A folder restored from the config is unavailable until the spaces manager knows its space. If the account connects before the + * drives reply arrives, scheduling on connect skips the folder, so it has to be scheduled once its space shows up. + */ + void testFolderIsScheduledWhenItsSpaceArrivesAfterConnect() + { + auto dir = TestUtils::createTempDir(); + QVERIFY(dir.isValid()); + QDir localDir(dir.path()); + // created while the client was not running, so the folder watcher never reports it + QVERIFY(localDir.mkpath(QStringLiteral("Folder1"))); + + FolderMan *folderman = TestUtils::folderMan(); + folderman->setSyncEnabled(true); + + auto *fakeAm = new FakeAM(FileInfo{}, nullptr); + auto *acc = new Account(QUuid::createUuid(), QStringLiteral("admin"), QUrl(QStringLiteral("http://localhost/owncloud"))); + acc->setCredentials(new FakeCredentials(acc, fakeAm, acc)); + acc->setDavDisplayName(QStringLiteral("fakename") + acc->uuid().toString(QUuid::WithoutBraces)); + acc->setCapabilities({acc->url(), TestUtils::testCapabilities()}); + + const QString spaceId = QUuid::createUuid().toString(QUuid::WithoutBraces); + const QJsonObject drive{{QStringLiteral("id"), spaceId}, {QStringLiteral("driveType"), QStringLiteral("personal")}, + {QStringLiteral("name"), QStringLiteral("Personal")}, + {QStringLiteral("root"), + QJsonObject{ + {QStringLiteral("id"), spaceId}, {QStringLiteral("eTag"), QStringLiteral("1")}, {QStringLiteral("webDavUrl"), acc->davUrl().toString()}}}}; + const QByteArray drivesReply = QJsonDocument(QJsonObject{{QStringLiteral("value"), QJsonArray{drive}}}).toJson(); + // hold the drives back until the account is connected, like the delayed reply in the GUI test run + bool serveDrives = false; + fakeAm->setOverride([&](QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice *) -> QNetworkReply * { + if (request.url().path().endsWith(QLatin1String("/graph/v1.0/me/drives"))) { + if (!serveDrives) { + return new FakeErrorReply(op, request, fakeAm, 503); + } + return new FakePayloadReply(op, request, drivesReply, fakeAm); + } + return nullptr; + }); + + TestUtils::TestUtilsPrivate::AccountStateRaii accountState( + AccountManager::instance()->addAccount(acc), &TestUtils::TestUtilsPrivate::accountStateDeleter); + + FolderDefinition definition(acc->davUrl(), spaceId, QStringLiteral("Personal")); + definition.setLocalPath(localDir.canonicalPath()); + definition.setJournalPath(SyncJournalDb::makeDbName(definition.localPath())); + Folder *folder = folderman->addFolder(accountState.get(), definition); + QVERIFY(folder); + // what addFoldersFromConfigByAccount does while the spaces manager is still empty + folder->setAvailable(folder->space() != nullptr); + QVERIFY(!folder->isAvailable()); + folderman->setUpInitialSpaces(accountState.get()); + + QSignalSpy syncStarted(folder, &Folder::syncStarted); + QSignalSpy syncFinished(folder, &Folder::syncFinished); + QTRY_VERIFY(folder->isReady()); + // FakeCredentials never fetch, so report the connection validator result directly + QVERIFY(QMetaObject::invokeMethod(accountState.get(), "slotConnectionValidatorResult", Qt::DirectConnection, + Q_ARG(OCC::ConnectionValidator::Status, ConnectionValidator::Connected), Q_ARG(QStringList, {}))); + QVERIFY(accountState->isConnected()); + QVERIFY(!folder->canSync()); + QCOMPARE(syncStarted.count(), 0); + + serveDrives = true; + // SpacesManager::refresh() is private; its refresh timer is what fetches the drives again + auto *refreshTimer = acc->spacesManager()->findChild(); + QVERIFY(refreshTimer); + refreshTimer->start(0); + QTRY_VERIFY(folder->isAvailable()); + refreshTimer->stop(); + + QTRY_VERIFY(!syncFinished.isEmpty()); + QVERIFY(fakeAm->currentRemoteState().find(QStringLiteral("Folder1"))); + } }; QTEST_GUILESS_MAIN(TestFolderMan) From 53e7f2b0debd2ef836c673713fcea89c924b043c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= <323649642+oc-tmueller@users.noreply.github.com> Date: Thu, 3 Dec 2026 15:02:15 +0100 Subject: [PATCH 2/4] chore: add changelog entry for #12770 Co-Authored-By: Claude Opus 5.5 --- changelog/unreleased/12770.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 changelog/unreleased/12770.md diff --git a/changelog/unreleased/12770.md b/changelog/unreleased/12770.md new file mode 100644 index 00000000000..6209dea64be --- /dev/null +++ b/changelog/unreleased/12770.md @@ -0,0 +1,8 @@ +Bugfix: Sync folders whose space is loaded after the account connected + +When the client started and connected to the server before the list of +spaces had arrived, folders restored from the configuration were never +scheduled. Changes made while the client was not running were only synced +once something changed on the server or on disk. + +https://github.com/owncloud/client/pull/12770 From 8390982de7888c8418bedf232b15b27f1687d691 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= <323649642+oc-tmueller@users.noreply.github.com> Date: Thu, 3 Dec 2026 15:05:28 +0100 Subject: [PATCH 3/4] fix: enqueue a folder only when it becomes available loadSpacesAlone calls onSpacesAdded and then gets spacesAdded for the same spaces, which synced the folder twice. Also capture the test's fake network state by value so a late request cannot read the test's dead locals. Co-Authored-By: Claude Opus 5.5 --- src/gui/folderman.cpp | 3 ++- test/testfolderman.cpp | 21 +++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp index f5146f6e559..d4fa9831208 100644 --- a/src/gui/folderman.cpp +++ b/src/gui/folderman.cpp @@ -443,9 +443,10 @@ void FolderMan::onSpacesAdded(const QUuid &accountId, QList s else if (_folders.contains(accountId) && _folders[accountId].contains(space->id())) { newUnsyncedSpaces.remove(space); Folder *folder = _folders[accountId][space->id()]; + const bool wasAvailable = folder->isAvailable(); folder->setAvailable(true); // a folder restored from the config was skipped when the account connected because its space was not known yet - if (folder->canSync()) { + if (!wasAvailable && folder->canSync()) { _scheduler->enqueueFolder(folder); } } diff --git a/test/testfolderman.cpp b/test/testfolderman.cpp index 1745a609694..ffcf9e6c013 100644 --- a/test/testfolderman.cpp +++ b/test/testfolderman.cpp @@ -318,16 +318,17 @@ private Q_SLOTS: {QStringLiteral("id"), spaceId}, {QStringLiteral("eTag"), QStringLiteral("1")}, {QStringLiteral("webDavUrl"), acc->davUrl().toString()}}}}; const QByteArray drivesReply = QJsonDocument(QJsonObject{{QStringLiteral("value"), QJsonArray{drive}}}).toJson(); // hold the drives back until the account is connected, like the delayed reply in the GUI test run - bool serveDrives = false; - fakeAm->setOverride([&](QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice *) -> QNetworkReply * { - if (request.url().path().endsWith(QLatin1String("/graph/v1.0/me/drives"))) { - if (!serveDrives) { - return new FakeErrorReply(op, request, fakeAm, 503); + auto serveDrives = std::make_shared(false); + fakeAm->setOverride( + [serveDrives, drivesReply, fakeAm](QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice *) -> QNetworkReply * { + if (request.url().path().endsWith(QLatin1String("/graph/v1.0/me/drives"))) { + if (!*serveDrives) { + return new FakeErrorReply(op, request, fakeAm, 503); + } + return new FakePayloadReply(op, request, drivesReply, fakeAm); } - return new FakePayloadReply(op, request, drivesReply, fakeAm); - } - return nullptr; - }); + return nullptr; + }); TestUtils::TestUtilsPrivate::AccountStateRaii accountState( AccountManager::instance()->addAccount(acc), &TestUtils::TestUtilsPrivate::accountStateDeleter); @@ -352,7 +353,7 @@ private Q_SLOTS: QVERIFY(!folder->canSync()); QCOMPARE(syncStarted.count(), 0); - serveDrives = true; + *serveDrives = true; // SpacesManager::refresh() is private; its refresh timer is what fetches the drives again auto *refreshTimer = acc->spacesManager()->findChild(); QVERIFY(refreshTimer); From cbc043b83955a2fcb8f7eefea3e549d6072da119 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= <323649642+oc-tmueller@users.noreply.github.com> Date: Thu, 3 Dec 2026 15:59:39 +0100 Subject: [PATCH 4/4] test: give the fake space the folder definition's dav url FolderDefinition drops the trailing slash of the dav url, and Folder::webDavUrl() asserts that the space url matches it. Release builds compile the assert out, so the test passed locally and aborted in CI. Co-Authored-By: Claude Opus 5.5 --- test/testfolderman.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/test/testfolderman.cpp b/test/testfolderman.cpp index ffcf9e6c013..c0c625434bf 100644 --- a/test/testfolderman.cpp +++ b/test/testfolderman.cpp @@ -311,11 +311,15 @@ private Q_SLOTS: acc->setCapabilities({acc->url(), TestUtils::testCapabilities()}); const QString spaceId = QUuid::createUuid().toString(QUuid::WithoutBraces); + // the definition drops the trailing slash of the dav url; Folder::webDavUrl() asserts that the space url matches it + FolderDefinition definition(acc->davUrl(), spaceId, QStringLiteral("Personal")); + definition.setLocalPath(localDir.canonicalPath()); + definition.setJournalPath(SyncJournalDb::makeDbName(definition.localPath())); const QJsonObject drive{{QStringLiteral("id"), spaceId}, {QStringLiteral("driveType"), QStringLiteral("personal")}, {QStringLiteral("name"), QStringLiteral("Personal")}, {QStringLiteral("root"), - QJsonObject{ - {QStringLiteral("id"), spaceId}, {QStringLiteral("eTag"), QStringLiteral("1")}, {QStringLiteral("webDavUrl"), acc->davUrl().toString()}}}}; + QJsonObject{{QStringLiteral("id"), spaceId}, {QStringLiteral("eTag"), QStringLiteral("1")}, + {QStringLiteral("webDavUrl"), definition.webDavUrl().toString()}}}}; const QByteArray drivesReply = QJsonDocument(QJsonObject{{QStringLiteral("value"), QJsonArray{drive}}}).toJson(); // hold the drives back until the account is connected, like the delayed reply in the GUI test run auto serveDrives = std::make_shared(false); @@ -333,9 +337,6 @@ private Q_SLOTS: TestUtils::TestUtilsPrivate::AccountStateRaii accountState( AccountManager::instance()->addAccount(acc), &TestUtils::TestUtilsPrivate::accountStateDeleter); - FolderDefinition definition(acc->davUrl(), spaceId, QStringLiteral("Personal")); - definition.setLocalPath(localDir.canonicalPath()); - definition.setJournalPath(SyncJournalDb::makeDbName(definition.localPath())); Folder *folder = folderman->addFolder(accountState.get(), definition); QVERIFY(folder); // what addFoldersFromConfigByAccount does while the spaces manager is still empty