From c71f5612da69b11d74c782594f26dbe628a6f113 Mon Sep 17 00:00:00 2001 From: Patrick Cernko Date: Fri, 1 Sep 2023 11:30:46 +0200 Subject: [PATCH] fixed detection of server version in cmd client similar to gui client: first check status.php for version and then capabilities, only use version string if not empty this also fixes 'File names containing the character ":" are not supported on this file system.' errors in nextcloudcmd (on Linux): The invalidFilenameRegex was set to a static default in case the server version was not set correctly. As newer versions of nextcloud do not return the version in capabilities but status.php, the server version was empty. --- src/cmd/cmd.cpp | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/cmd/cmd.cpp b/src/cmd/cmd.cpp index 37c456dd1ae0f..2764f7255d19f 100644 --- a/src/cmd/cmd.cpp +++ b/src/cmd/cmd.cpp @@ -442,12 +442,40 @@ int main(int argc, char **argv) account->setTrustCertificates(options.trustSSL); QEventLoop loop; + auto *csjob = new CheckServerJob(account); + csjob->setIgnoreCredentialFailure(true); + QObject::connect(csjob, &CheckServerJob::instanceFound, [&](const QUrl &, const QJsonObject &info) { + // see ConnectionValidator::slotCapabilitiesRecieved: only set server version if not empty + QString serverVersion = CheckServerJob::version(info); + if (!serverVersion.isEmpty()) { + account->setServerVersion(serverVersion); + } + loop.quit(); + }); + QObject::connect(csjob, &CheckServerJob::instanceNotFound, [&]() { + loop.quit(); + }); + QObject::connect(csjob, &CheckServerJob::timeout, [&](const QUrl &) { + loop.quit(); + }); + csjob->start(); + loop.exec(); + + if (csjob->reply()->error() != QNetworkReply::NoError){ + std::cout<<"Error connecting to server for status\n"; + return EXIT_FAILURE; + } + auto *job = new JsonApiJob(account, QLatin1String("ocs/v1.php/cloud/capabilities")); QObject::connect(job, &JsonApiJob::jsonReceived, [&](const QJsonDocument &json) { auto caps = json.object().value("ocs").toObject().value("data").toObject().value("capabilities").toObject(); qDebug() << "Server capabilities" << caps; account->setCapabilities(caps.toVariantMap()); - account->setServerVersion(caps["core"].toObject()["status"].toObject()["version"].toString()); + // see ConnectionValidator::slotCapabilitiesRecieved: only set server version if not empty + QString serverVersion = caps["core"].toObject()["status"].toObject()["version"].toString(); + if (!serverVersion.isEmpty()) { + account->setServerVersion(serverVersion); + } loop.quit(); }); job->start();