From abcbdfb93b10402968ef14bdd9d515ada2256e09 Mon Sep 17 00:00:00 2001 From: Matthieu Gallien Date: Fri, 3 Jul 2026 13:56:39 +0200 Subject: [PATCH 1/2] fix(accountsetup): exit with code 1 when sync folder creation fails during provisioning When FolderMan::addFolder() returns null in setupLocalSyncFolder, the isFailure argument was false, causing the process to exit with code 0 and suppress the warning log. The documented contract for non-interactive provisioning is exit code 1 on failure. Assisted-by: ClaudeCode:claude-sonnet-4-6 Signed-off-by: Matthieu Gallien --- src/gui/accountsetupfromcommandlinejob.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/accountsetupfromcommandlinejob.cpp b/src/gui/accountsetupfromcommandlinejob.cpp index 33044a0d74336..ed72a5ae6e950 100644 --- a/src/gui/accountsetupfromcommandlinejob.cpp +++ b/src/gui/accountsetupfromcommandlinejob.cpp @@ -194,7 +194,7 @@ void AccountSetupFromCommandLineJob::setupLocalSyncFolder(AccountState *accountS AccountManager::instance()->deleteAccount(accountState); printAccountSetupFromCommandLineStatusAndExit( QStringLiteral("Account %1 setup from command line failed, due to folder creation failure.").arg(_account->displayName()), - false); + true); } } From 1f6dd6601082b8b264b1055a840434babbfbf461 Mon Sep 17 00:00:00 2001 From: Matthieu Gallien Date: Fri, 3 Jul 2026 18:58:54 +0200 Subject: [PATCH 2/2] fix(account/setup): fix automated account creation via CLI options Signed-off-by: Matthieu Gallien --- src/gui/accountmanager.cpp | 6 ++++-- src/gui/accountsetupcommandlinemanager.cpp | 2 +- src/gui/accountsetupfromcommandlinejob.cpp | 8 ++++++++ src/gui/application.cpp | 17 +++++++++++------ src/gui/systray.cpp | 6 ++++-- 5 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/gui/accountmanager.cpp b/src/gui/accountmanager.cpp index 0158c22488ef8..f7b575d36dfc9 100644 --- a/src/gui/accountmanager.cpp +++ b/src/gui/accountmanager.cpp @@ -873,8 +873,10 @@ AccountPtr AccountManager::createAccount() acc->setSslErrorHandler(new SslDialogErrorHandler); connect(acc.data(), &Account::proxyAuthenticationRequired, ProxyAuthHandler::instance(), &ProxyAuthHandler::handleProxyAuthenticationRequired); - connect(acc.data(), &Account::lockFileError, - Systray::instance(), &Systray::showErrorMessageDialog); + if (Systray::instance()) { + connect(acc.data(), &Account::lockFileError, + Systray::instance(), &Systray::showErrorMessageDialog); + } return acc; } diff --git a/src/gui/accountsetupcommandlinemanager.cpp b/src/gui/accountsetupcommandlinemanager.cpp index 8d89213cfe73f..de1b0ec4cf54e 100644 --- a/src/gui/accountsetupcommandlinemanager.cpp +++ b/src/gui/accountsetupcommandlinemanager.cpp @@ -83,7 +83,7 @@ bool AccountSetupCommandLineManager::parseCommandlineOption(const QString &optio bool AccountSetupCommandLineManager::isCommandLineParsed() const { - return !_appPassword.isEmpty() && !_userId.isEmpty() && _serverUrl.isValid(); + return !_userId.isEmpty() && _serverUrl.isValid(); } bool AccountSetupCommandLineManager::isVfsEnabled() const diff --git a/src/gui/accountsetupfromcommandlinejob.cpp b/src/gui/accountsetupfromcommandlinejob.cpp index ed72a5ae6e950..397d26607b38a 100644 --- a/src/gui/accountsetupfromcommandlinejob.cpp +++ b/src/gui/accountsetupfromcommandlinejob.cpp @@ -19,6 +19,8 @@ #include #include +using namespace Qt::StringLiterals; + namespace OCC { Q_LOGGING_CATEGORY(lcAccountSetupCommandLineJob, "nextcloud.gui.accountsetupcommandlinejob", QtInfoMsg) @@ -70,8 +72,14 @@ void AccountSetupFromCommandLineJob::handleAccountSetupFromCommandLine() const auto credentials = new WebFlowCredentials(_userId, _appPassword); _account = AccountManager::createAccount(); + _account->setCredentials(credentials); + _account->setCredentialSetting(u"user"_s, _userId); _account->setUrl(_serverUrl); + auto accountState = AccountManager::instance()->addAccount(_account); + setupLocalSyncFolder(accountState); + + Q_EMIT _account->wantsAccountSaved(_account); fetchUserName(); } diff --git a/src/gui/application.cpp b/src/gui/application.cpp index 40cba58df8b56..8da2fc1f98e9d 100644 --- a/src/gui/application.cpp +++ b/src/gui/application.cpp @@ -344,7 +344,7 @@ Application::Application(int &argc, char **argv) // try to migrate legacy accounts and folders from a previous client version // only copy the settings and check what should be skipped - if (!configVersionMigration()) { + if (!AccountSetupCommandLineManager::instance()->isCommandLineParsed() && !configVersionMigration()) { qCWarning(lcApplication) << "Config version migration was not possible."; } @@ -412,6 +412,16 @@ Application::Application(int &argc, char **argv) connect(&_singleApp, &KDSingleApplication::messageReceived, this, &Application::slotParseMessage); #endif + if (AccountSetupCommandLineManager::instance()->isCommandLineParsed()) { + _folderManager.reset(new FolderMan); + AccountSetupCommandLineManager::instance()->setupAccountFromCommandLine(); + _quitInstance = true; + } + AccountSetupCommandLineManager::destroy(); + if (_quitInstance) { + return; + } + // create accounts and folders from a legacy desktop client or from the current config file setupAccountsAndFolders(); @@ -501,11 +511,6 @@ Application::Application(int &argc, char **argv) } #endif - if (AccountSetupCommandLineManager::instance()->isCommandLineParsed()) { - AccountSetupCommandLineManager::instance()->setupAccountFromCommandLine(); - } - AccountSetupCommandLineManager::destroy(); - #if defined(BUILD_FILE_PROVIDER_MODULE) Mac::FileProvider::instance(); if (Mac::FileProvider::available()) { diff --git a/src/gui/systray.cpp b/src/gui/systray.cpp index d9641b09be0fb..9c08aff4285df 100644 --- a/src/gui/systray.cpp +++ b/src/gui/systray.cpp @@ -108,8 +108,10 @@ Systray::Systray() this, [this]{ showWindow(WindowPosition::Center); }); #endif - connect(FolderMan::instance(), &FolderMan::folderListChanged, this, &Systray::slotSyncFoldersChanged); - slotSyncFoldersChanged(FolderMan::instance()->map()); + if (FolderMan::instance()) { + connect(FolderMan::instance(), &FolderMan::folderListChanged, this, &Systray::slotSyncFoldersChanged); + slotSyncFoldersChanged(FolderMan::instance()->map()); + } } void Systray::create()