fix: Crash when disabling file provider for account with UUID as name.

Signed-off-by: Iva Horn <iva.horn@nextcloud.com>
This commit is contained in:
Iva Horn 2025-10-23 14:47:19 +02:00
parent b240648fd0
commit d509974bfd

View File

@ -591,7 +591,7 @@ public:
} }
} }
QStringList configuredDomainIds() const QStringList getAccountIdsOfFoundFileProviderDomains() const
{ {
return _registeredDomains.keys(); return _registeredDomains.keys();
} }
@ -652,34 +652,36 @@ void FileProviderDomainManager::updateFileProviderDomains()
return; return;
} }
const auto vfsEnabledAccounts = FileProviderSettingsController::instance()->vfsEnabledAccounts(); const auto fileProviderEnabledAccountIds = FileProviderSettingsController::instance()->vfsEnabledAccounts();
auto configuredDomains = d->configuredDomainIds(); auto accountIdsOfFoundFileProviderDomains = d->getAccountIdsOfFoundFileProviderDomains();
for (const auto &accountUserIdAtHost : vfsEnabledAccounts) { for (const auto &fileProviderEnabledAccountId : fileProviderEnabledAccountIds) {
// If the domain has already been set up for this account, then don't set it up again // If the domain has already been set up for this account, then don't set it up again.
if (configuredDomains.contains(accountUserIdAtHost)) { if (accountIdsOfFoundFileProviderDomains.contains(fileProviderEnabledAccountId)) {
configuredDomains.removeAll(accountUserIdAtHost); accountIdsOfFoundFileProviderDomains.removeAll(fileProviderEnabledAccountId);
continue; continue;
} }
if (const auto accountState = AccountManager::instance()->accountFromUserId(accountUserIdAtHost)) { if (const auto accountState = AccountManager::instance()->accountFromUserId(fileProviderEnabledAccountId)) {
qCDebug(lcMacFileProviderDomainManager) << "Succeed in fetching account state by account id" qCDebug(lcMacFileProviderDomainManager) << "Succeed in fetching account state by account id"
<< accountUserIdAtHost << fileProviderEnabledAccountId
<< ", adding file provider domain for account."; << ", adding file provider domain for account.";
addFileProviderDomainForAccount(accountState.data()); addFileProviderDomainForAccount(accountState.data());
} else { } else {
qCWarning(lcMacFileProviderDomainManager) << "Could not fetch account state by account id" qCWarning(lcMacFileProviderDomainManager) << "Could not fetch account state by account id"
<< accountUserIdAtHost << fileProviderEnabledAccountId
<< ", removing account from list of VFS-enabled accounts."; << ", removing account from list of VFS-enabled accounts.";
FileProviderSettingsController::instance()->setVfsEnabledForAccount(accountUserIdAtHost, false); FileProviderSettingsController::instance()->setVfsEnabledForAccount(fileProviderEnabledAccountId, false);
} }
} }
for (const auto &remainingDomainUserId : configuredDomains) { for (const auto &remainingAccountId : accountIdsOfFoundFileProviderDomains) {
const auto accountId = accountIdFromDomainId(remainingDomainUserId); qCDebug(lcMacFileProviderDomainManager) << "Orphaned file provider domain to remove found for account id"
const auto accountState = AccountManager::instance()->accountFromUserId(accountId); << remainingAccountId;
const auto accountState = AccountManager::instance()->accountFromUserId(remainingAccountId);
removeFileProviderDomainForAccount(accountState.data()); removeFileProviderDomainForAccount(accountState.data());
} }
@ -721,9 +723,6 @@ void FileProviderDomainManager::removeFileProviderDomainForAccount(const Account
} }
Q_ASSERT(accountState); Q_ASSERT(accountState);
const auto account = accountState->account();
Q_ASSERT(account);
d->removeFileProviderDomain(accountState); d->removeFileProviderDomain(accountState);
} }