From bf2ee8578cfabb0309a13277fa21164c1cbe1063 Mon Sep 17 00:00:00 2001 From: Robert Adam Date: Sun, 28 Aug 2022 18:28:59 +0200 Subject: [PATCH] FIX(server): Look for mumble-server* files Previously the server was only looking for files named e.g. murmur.ini or murmur.sqlite. With this commit, the server will now look first for files called mumble_server.ini and mumble_server.sqlite before falling back to the old names (for backwards compatibility). This is meant as a means to drive forward the server renaming from murmur(d) to mumble-server. --- src/murmur/Meta.cpp | 23 ++++++++++++++--------- src/murmur/ServerDB.cpp | 35 ++++++++++++++++++----------------- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/src/murmur/Meta.cpp b/src/murmur/Meta.cpp index c8a6455b6..88cb9cb3a 100644 --- a/src/murmur/Meta.cpp +++ b/src/murmur/Meta.cpp @@ -72,7 +72,7 @@ MetaParams::MetaParams() { iDBPort = 0; qsDBusService = "net.sourceforge.mumble.murmur"; qsDBDriver = "QSQLITE"; - qsLogfile = "murmur.log"; + qsLogfile = "mumble-server.log"; iLogDays = 31; @@ -169,6 +169,7 @@ void MetaParams::read(QString fname) { datapaths << appdir.absolutePath() + QLatin1String("/Mumble"); #else datapaths << QDir::homePath() + QLatin1String("/.murmurd"); + datapaths << QDir::homePath() + QLatin1String("/.mumble-server"); datapaths << QDir::homePath() + QLatin1String("/.config/Mumble"); #endif @@ -181,20 +182,24 @@ void MetaParams::read(QString fname) { datapaths << QDir::currentPath(); datapaths << QCoreApplication::instance()->applicationDirPath(); - foreach (const QString &p, datapaths) { + for (const QString &p : datapaths) { if (!p.isEmpty()) { - QFileInfo fi(p, "murmur.ini"); - if (fi.exists() && fi.isReadable()) { - qdBasePath = QDir(p); - qsAbsSettingsFilePath = fi.absoluteFilePath(); - break; + // Prefer "mumble-server.ini" but for legacy reasons also keep looking for "murmur.ini" + for (const QString ¤tFileName : + { QStringLiteral("mumble-server.ini"), QStringLiteral("murmur.ini") }) { + QFileInfo fi(p, currentFileName); + if (fi.exists() && fi.isReadable()) { + qdBasePath = QDir(p); + qsAbsSettingsFilePath = fi.absoluteFilePath(); + break; + } } } } if (qsAbsSettingsFilePath.isEmpty()) { QDir::root().mkpath(qdBasePath.absolutePath()); qdBasePath = QDir(datapaths.at(0)); - qsAbsSettingsFilePath = qdBasePath.absolutePath() + QLatin1String("/murmur.ini"); + qsAbsSettingsFilePath = qdBasePath.absolutePath() + QLatin1String("/mumble-server.ini"); } } else { QFile f(fname); @@ -562,7 +567,7 @@ bool MetaParams::loadSSLSettings() { QString qsSSLDHParamsIniValue = qsSettings->value(QLatin1String("sslDHParams")).toString(); if (!qsSSLDHParamsIniValue.isEmpty()) { qFatal("MetaParams: This version of Murmur does not support Diffie-Hellman parameters (sslDHParams). Murmur " - "will not start unless you remove the option from your murmur.ini file."); + "will not start unless you remove the option from your mumble-server.ini (murmur.ini)file."); return false; } #endif diff --git a/src/murmur/ServerDB.cpp b/src/murmur/ServerDB.cpp index 95bfbda1e..354dd041e 100644 --- a/src/murmur/ServerDB.cpp +++ b/src/murmur/ServerDB.cpp @@ -124,32 +124,33 @@ ServerDB::ServerDB() { found = db->open(); } else { QStringList datapaths; - int i; datapaths << Meta::mp.qdBasePath.absolutePath(); datapaths << QDir::currentPath(); datapaths << QCoreApplication::instance()->applicationDirPath(); datapaths << QDir::homePath(); - for (i = 0; (i < datapaths.size()) && !found; i++) { - if (!datapaths[i].isEmpty()) { - QFile f(datapaths[i] + "/murmur.sqlite"); - if (f.exists()) { - db->setDatabaseName(f.fileName()); - found = db->open(); - } - } - } + // We use a lambda, so we can easily "break out" of all levels of nested loops using return + [&]() { + for (bool searchExistingDB : { true, false }) { + for (const QString ¤tDir : datapaths) { + // Prefer "mumble-server.sqlite", but for legacy reasons also keep looking for "murmur.sqlite" + for (const QString ¤tFilename : + { QStringLiteral("mumble-server.sqlite"), QStringLiteral("murmur.sqlite") }) { + QFile currentFile(currentDir + "/" + currentFilename); - if (!found) { - for (i = 0; (i < datapaths.size()) && !found; i++) { - if (!datapaths[i].isEmpty()) { - QFile f(datapaths[i] + "/murmur.sqlite"); - db->setDatabaseName(f.fileName()); - found = db->open(); + if (!searchExistingDB || currentFile.exists()) { + db->setDatabaseName(currentFile.fileName()); + + if (db->open()) { + found = true; + return; + } + } + } } } - } + }(); } if (found) { QFileInfo fi(db->databaseName());