Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when updating enabled File Provider domains (macOS VFS) #6833

Merged
merged 6 commits into from
Jun 25, 2024
Merged
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
22 changes: 11 additions & 11 deletions src/gui/accountmanager.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check notice on line 1 in src/gui/accountmanager.cpp

View workflow job for this annotation

GitHub Actions / build

Run clang-format on src/gui/accountmanager.cpp

File src/gui/accountmanager.cpp does not conform to Custom style guidelines. (lines 109)
* Copyright (C) by Olivier Goffart <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -105,14 +105,13 @@
if (!skipSettingsKeys.contains(settings->group())) {
if (const auto acc = loadAccountHelper(*settings)) {
acc->_id = accountId;
if (auto accState = AccountState::loadFromSettings(acc, *settings)) {
auto jar = qobject_cast<CookieJar*>(acc->_am->cookieJar());
ASSERT(jar);
if (jar) {
jar->restore(acc->cookieJarPath());
}
addAccountState(accState);
const auto accState = new AccountState(acc);
const auto jar = qobject_cast<CookieJar*>(acc->_am->cookieJar());
Q_ASSERT(jar);
if (jar) {
jar->restore(acc->cookieJarPath());
}
addAccountState(accState);
}
} else {
qCInfo(lcAccountManager) << "Account" << accountId << "is too new, ignoring";
Expand Down Expand Up @@ -569,11 +568,12 @@
}
}

void AccountManager::addAccountState(AccountState *accountState)
void AccountManager::addAccountState(AccountState *const accountState)
{
QObject::connect(accountState->account().data(),
&Account::wantsAccountSaved,
this, &AccountManager::saveAccount);
Q_ASSERT(accountState);
Q_ASSERT(accountState->account());

QObject::connect(accountState->account().data(), &Account::wantsAccountSaved, this, &AccountManager::saveAccount);

AccountStatePtr ptr(accountState);
_accounts << ptr;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/accountmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#pragma once

#include "account.h"

Check failure on line 17 in src/gui/accountmanager.h

View workflow job for this annotation

GitHub Actions / build

src/gui/accountmanager.h:17:10 [clang-diagnostic-error]

'account.h' file not found
#include "accountstate.h"

namespace OCC {
Expand Down Expand Up @@ -126,7 +126,7 @@
[[nodiscard]] QString generateFreeAccountId() const;

// Adds an account to the tracked list, emitting accountAdded()
void addAccountState(AccountState *accountState);
void addAccountState(AccountState *const accountState);

AccountManager() = default;
QList<AccountStatePtr> _accounts;
Expand Down
8 changes: 1 addition & 7 deletions src/gui/accountstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace OCC {

Q_LOGGING_CATEGORY(lcAccountState, "nextcloud.gui.account.state", QtInfoMsg)

AccountState::AccountState(AccountPtr account)
AccountState::AccountState(const AccountPtr &account)
: QObject()
, _account(account)
, _state(AccountState::Disconnected)
Expand Down Expand Up @@ -85,12 +85,6 @@ AccountState::AccountState(AccountPtr account)

AccountState::~AccountState() = default;

AccountState *AccountState::loadFromSettings(AccountPtr account, QSettings & /*settings*/)
{
auto accountState = new AccountState(account);
return accountState;
}

AccountPtr AccountState::account() const
{
return _account;
Expand Down
8 changes: 1 addition & 7 deletions src/gui/accountstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,9 @@ class AccountState : public QObject, public QSharedData
using ConnectionStatus = ConnectionValidator::Status;

/// Use the account as parent
explicit AccountState(AccountPtr account);
explicit AccountState(const AccountPtr &account);
~AccountState() override;

/** Creates an account state from settings and an Account object.
*
* Use from AccountManager with a prepared QSettings object only.
*/
static AccountState *loadFromSettings(AccountPtr account, QSettings &settings);

AccountPtr account() const;

ConnectionStatus connectionStatus() const;
Expand Down
10 changes: 8 additions & 2 deletions src/gui/macOS/fileproviderdomainmanager_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -453,13 +453,19 @@ QStringList configuredDomainIds() const
auto configuredDomains = d->configuredDomainIds();

for (const auto &accountUserIdAtHost : vfsEnabledAccounts) {
// If the domain has already been set up for this account, then don't set it up again
if (configuredDomains.contains(accountUserIdAtHost)) {
configuredDomains.removeAll(accountUserIdAtHost);
continue;
}

const auto accountState = AccountManager::instance()->accountFromUserId(accountUserIdAtHost);
addFileProviderDomainForAccount(accountState.data());
if (const auto accountState = AccountManager::instance()->accountFromUserId(accountUserIdAtHost)) {
addFileProviderDomainForAccount(accountState.data());
} else {
qCWarning(lcMacFileProviderDomainManager) << "Could not find account for file provider domain:" << accountUserIdAtHost
<< "removing account from list of vfs-enabled accounts.";
FileProviderSettingsController::instance()->setVfsEnabledForAccount(accountUserIdAtHost, false);
}
}

for (const auto &remainingDomainUserId : configuredDomains) {
Expand Down
3 changes: 1 addition & 2 deletions src/libsync/account.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#ifndef SERVERCONNECTION_H
#define SERVERCONNECTION_H

#include "accountfwd.h"
#include "capabilities.h"
#include "clientsideencryption.h"
#include "clientstatusreporting.h"
Expand Down Expand Up @@ -55,8 +56,6 @@ class ReadPasswordJob;
namespace OCC {

class AbstractCredentials;
class Account;
using AccountPtr = QSharedPointer<Account>;
class AccessManager;
class SimpleNetworkJob;
class PushNotifications;
Expand Down
Loading