Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions changelog/unreleased/12770.md
Original file line number Diff line number Diff line change
@@ -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
8 changes: 7 additions & 1 deletion src/gui/folderman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,13 @@ void FolderMan::onSpacesAdded(const QUuid &accountId, QList<GraphApi::Space *> 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()];
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 (!wasAvailable && folder->canSync()) {
_scheduler->enqueueFolder(folder);
}
}
}

Expand Down
82 changes: 81 additions & 1 deletion test/testfolderman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
#include <QTemporaryDir>
#include <QtTest>

#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"
Expand Down Expand Up @@ -285,6 +288,83 @@ 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);
// 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"), 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<bool>(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 nullptr;
});

TestUtils::TestUtilsPrivate::AccountStateRaii accountState(
AccountManager::instance()->addAccount(acc), &TestUtils::TestUtilsPrivate::accountStateDeleter);

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<QTimer *>();
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)
Expand Down
Loading