diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp index 6a6c7de3670da..bcb9cf34640e8 100644 --- a/src/gui/folderman.cpp +++ b/src/gui/folderman.cpp @@ -1109,6 +1109,13 @@ bool FolderMan::isSwitchToVfsNeeded(const FolderDefinition &folderDefinition) co return result; } +#ifdef BUILD_FILE_PROVIDER_MODULE +bool FolderMan::canPollFileProviderEtag(const AccountState &accountState) +{ + return accountState.isConnected(); +} +#endif + void FolderMan::slotEtagPollTimerTimeout() { qCInfo(lcFolderMan) << "Etag poll timer timeout"; @@ -1139,6 +1146,11 @@ void FolderMan::slotEtagPollTimerTimeout() for (const auto &accountState : accounts) { const auto account = accountState->account(); + if (!canPollFileProviderEtag(*accountState)) { + qCDebug(lcFolderMan) << "Account" << account->displayName() << "is not connected, skipping File Provider ETag check."; + continue; + } + // Skip accounts that don't have a File Provider domain if (!Mac::FileProvider::instance()->domainManager()->domainForAccount(account.data())) { qCDebug(lcFolderMan) << "Account" << account->displayName() << "has no file provider domain, skipping."; diff --git a/src/gui/folderman.h b/src/gui/folderman.h index 575cafd881c1a..e5722a25dd7ac 100644 --- a/src/gui/folderman.h +++ b/src/gui/folderman.h @@ -357,6 +357,11 @@ private slots: void runEtagJobsIfPossible(const QList &folderMap); void runEtagJobIfPossible(Folder *folder); +#ifdef BUILD_FILE_PROVIDER_MODULE + /** @brief Returns whether the account state permits File Provider ETag polling. */ + [[nodiscard]] static bool canPollFileProviderEtag(const AccountState &accountState); +#endif + bool pushNotificationsFilesReady(const OCC::AccountPtr &account); [[nodiscard]] bool isSwitchToVfsNeeded(const FolderDefinition &folderDefinition) const; diff --git a/test/testfolderman.cpp b/test/testfolderman.cpp index e06761a13bf8a..277ed2da91dae 100644 --- a/test/testfolderman.cpp +++ b/test/testfolderman.cpp @@ -609,6 +609,30 @@ private slots: } #ifdef BUILD_FILE_PROVIDER_MODULE + void testFileProviderEtagPollingRequiresConnectedAccount() + { + const auto accountState = std::make_unique(Account::create()); + QVERIFY(FolderMan::canPollFileProviderEtag(*accountState)); + + const auto disconnectedStates = { + AccountState::SignedOut, + AccountState::Disconnected, + AccountState::ServiceUnavailable, + AccountState::RedirectDetected, + AccountState::MaintenanceMode, + AccountState::NetworkError, + AccountState::ConfigurationError, + AccountState::AskingCredentials, + AccountState::NeedToSignTermsOfService, + }; + + for (const auto state : disconnectedStates) { + accountState->setStateForTesting(state); + QVERIFY2(!FolderMan::canPollFileProviderEtag(*accountState), + qPrintable(AccountState::stateString(state))); + } + } + void testAddFolderRefusedWhenFileProviderModeEnabled() { _fm.reset({});