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(client) : Fixed config directory path assignment #6186

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

supersanban
Copy link

Config directory path in Linux should be picked from XDG_CONFIG_HOME environment variable.

Fixes #6029

Checks

@supersanban supersanban changed the title FIX(server) : Fixed config directory path assignment FIX(client) : Fixed config directory path assignment Aug 4, 2023
Copy link
Member

@Krzmbrzl Krzmbrzl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change your commit message to what you have chosen for the PR title (git commit --amend) and also add the Fixes #6029 into the commit message body

src/mumble/Database.cpp Outdated Show resolved Hide resolved
@supersanban supersanban force-pushed the issue-6029 branch 2 times, most recently from dc7c958 to bac0167 Compare August 5, 2023 18:05
src/mumble/Database.cpp Outdated Show resolved Hide resolved
@supersanban supersanban force-pushed the issue-6029 branch 2 times, most recently from ac70883 to bf2a73b Compare August 7, 2023 13:33
src/mumble/Database.cpp Outdated Show resolved Hide resolved
Config directory path in Linux should be picked from XDG_CONFIG_HOME environment variable

Fixes mumble-voip#6029
@Hartmnt
Copy link
Member

Hartmnt commented Aug 7, 2023

Has anyone actually verified that this fixes #6029?

If I understand correctly, the order of datapaths determines the preferred location to read from and write to. That means the mumble.sqlite, if it does not already exist, will be preferably placed in:

	datapaths << Global::get().qdBasePath.absolutePath();
	datapaths << QStandardPaths::writableLocation(QStandardPaths::DataLocation);

in that order, where qdBasePath refers to this line of code which resolves QStandardPaths::AppDataLocation to ~/.local/share/<APPNAME> [1].

The second entry is QStandardPaths::DataLocation is deprecated in Qt5 [2] and the same as QStandardPaths::AppDataLocation and QStandardPaths::AppLocalDataLocation (on Linux) and REMOVED in Qt6 [1]

Now as I see it, the changed code is only triggered, if ~/.local/share/<APPNAME> does not already contain a Mumble file and is not writable - which is possible, but unlikely on most systems.
The Qt documentation lists ~/.local/share[...]. Are we actually sure the ~ will be XDG_HOME or whatever it is exactly?
I am actually unable to find a reliable Qt source that states, if XDG is honored on Linux with regards to the QStandardPaths class...

I can barely wrap my head about the problem at this point. Can we have some decision matrix/table or something to visualize what is supposed to be stored where and when?

[1] https://doc.qt.io/qt-6/qstandardpaths.html
[2] https://doc.qt.io/qt-5/qstandardpaths.html

@Hartmnt
Copy link
Member

Hartmnt commented Aug 7, 2023

Additional information:

On my very little used Mumble test VM, there is a ~/.local/share/Mumble/Mumble which contains the mumble.sqlite and the Themes and Plugins folder, as I would expect given my previous explanation. But there is also a ~/.config/Mumble/Mumble which contains the mumble_settings.json
So we have to at least also consider this function

@Krzmbrzl
Copy link
Member

Krzmbrzl commented Aug 7, 2023

Has anyone actually verified that this fixes #6029?

I haven't. My thinking was that so far, the hard-coded path in the home-directory was used and this path has now been replaced by the XDG_CONFIG_HOME variable - if present.
However, we should indeed fix the logic here.

Other than that, this PR should probably also address the location of the settings JSON file:

mumble/src/mumble/Settings.cpp

Lines 1273 to 1322 in c338d1d

QString Settings::findSettingsLocation(bool legacy, bool *foundExistingFile) const {
// In order to make sure we'll find (mostly legacy) settings files, even if they end up being in a slightly
// different dir than we currently expect, we construct a search path list that we'll traverse while searching for
// the settings file. In case we find a suitable settings file within the search path, then we'll continue to use
// this path instead of creating a new one (in the location that we currently think is best to use).
QStringList paths;
paths << QCoreApplication::instance()->applicationDirPath();
paths << QStandardPaths::writableLocation(QStandardPaths::DataLocation);
paths << QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation);
paths << QStandardPaths::writableLocation(QStandardPaths::ConfigLocation);
paths << QFileInfo(QSettings().fileName()).dir().absolutePath();
QStringList settingsFileNames = legacy ? QStringList({ QStringLiteral("mumble.conf"), QStringLiteral("Mumble.conf"),
QStringLiteral("mumble.ini"), QStringLiteral("Mumble.ini") })
: QStringList({ QStringLiteral("mumble_settings.json") });
QString chosenPath;
for (const QString &settingsFileName : settingsFileNames) {
for (const QString &currentPath : paths) {
QFile settingsFile(QString::fromLatin1("%1/%2").arg(currentPath).arg(settingsFileName));
if (settingsFile.exists() && settingsFile.permissions().testFlag(QFile::WriteUser)) {
// Found existing settings file -> use that
chosenPath = QFileInfo(settingsFile).absoluteFilePath();
break;
}
}
}
if (foundExistingFile) {
*foundExistingFile = !chosenPath.isEmpty();
}
if (chosenPath.isEmpty()) {
// We were unable to find an existing settings file -> Fall back to a default location
chosenPath = QString::fromLatin1("%1/%2")
.arg(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation))
.arg(settingsFileNames[0]);
// Note: QStandardPaths::AppConfigLocation will return a directory of the style <root>/<org>/<application> where
// <root> is the path to the general config related directory on the respective OS, <org> is the name of our
// organization and <application> is our application's name. In our case (at the time of writing this) <org> =
// <application> = Mumble, leading to a doubly nested "Mumble" directory. This should only be a cosmetic issue
// though.
}
return chosenPath;
}

Copy link
Member

@Krzmbrzl Krzmbrzl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@supersanban will you address the remaining issues?

@Krzmbrzl Krzmbrzl marked this pull request as draft December 30, 2023 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

XDG_CONFIG_HOME is not respected
4 participants