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

Change conf path XDG_CACHE_HOME to XDG_STATE_HOME #9755

Merged
2 changes: 1 addition & 1 deletion docs/topics/DownloadInstall.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ image::linux_store.png[]

The Snap and Flatpak options are sandboxed applications (more secure). The Native option is installed with the operating system files. Read more about the limitations of these options here: https://keepassxc.org/docs/#faq-appsnap-yubikey[KeePassXC Snap FAQ]

NOTE: KeePassXC stores a configuration file in `~/.cache` to remember window position, recent files, and other local settings. If you mount this folder to a tmpdisk you will lose settings after reboot.
NOTE: KeePassXC stores a configuration file in `~/.local/state` to remember window position, recent files, and other local settings. If you mount this folder to a tmpdisk you will lose settings after reboot.

=== macOS
To install the KeePassXC app on macOS, double click on the downloaded DMG file and use the click and drag option as shown:
Expand Down
32 changes: 31 additions & 1 deletion src/core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,26 @@ void Config::init(const QString& configFileName, const QString& localConfigFileN
QDir().rmdir(QFileInfo(localConfigFileName).absolutePath());
}

#if defined(Q_OS_LINUX)
// Upgrade from previous KeePassXC version which stores its config
// in ~/.cache on Linux instead of ~/.local/state.
// Move file to correct location before continuing.
QString oldLocalConfigPath;
oldLocalConfigPath = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + "/keepassxc";
QString suffix;
#ifdef QT_DEBUG
suffix = "_debug";
#endif
oldLocalConfigPath += QString("/keepassxc%1.ini").arg(suffix);
oldLocalConfigPath = QDir::toNativeSeparators(oldLocalConfigPath);
if (!localConfigFileName.isEmpty() && !QFile::exists(localConfigFileName) && QFile::exists(oldLocalConfigPath)) {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think you should check for localConfigFileName being empty. That's just something that shouldn't happen and would be an error elsewhere. I think you should just check if it exists and if not, then check the old location. The definition of oldLocalConfigPath can be moved into the smaller scope of the corresponding if statement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I missed that, the isEmpty there is not relevant, removed it with 2eecf98
I also understand that this is not optimal to generate oldLocalConfigPath on every startup, i changed the conditions and moved it inside the first if statement, we will only generated if the config is missing, fixed in d77ef9d

QDir().mkpath(QFileInfo(localConfigFileName).absolutePath());
QFile::copy(oldLocalConfigPath, localConfigFileName);
QFile::remove(oldLocalConfigPath);
QDir().rmdir(QFileInfo(oldLocalConfigPath).absolutePath());
}
#endif

m_settings.reset(new QSettings(configFileName, QSettings::IniFormat));
if (!localConfigFileName.isEmpty() && configFileName != localConfigFileName) {
m_localSettings.reset(new QSettings(localConfigFileName, QSettings::IniFormat));
Expand Down Expand Up @@ -512,7 +532,17 @@ QPair<QString, QString> Config::defaultConfigFiles()
#else
// On case-sensitive Operating Systems, force use of lowercase app directories
configPath = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + "/keepassxc";
localConfigPath = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + "/keepassxc";
// Qt does not support XDG_STATE_HOME yet, change this once XDG_STATE_HOME is added
QString xdgStateHome;
xdgStateHome = QFile::decodeName(qgetenv("XDG_STATE_HOME"));
Copy link
Member

Choose a reason for hiding this comment

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

Combine these two.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My bad, fixed with 0cd5ce4

if (!xdgStateHome.startsWith(u'/')) {
xdgStateHome.clear(); // spec says relative paths should be ignored
}
if (xdgStateHome.isEmpty()) {
xdgStateHome = QDir::homePath() + "/.local/state";
}

localConfigPath = xdgStateHome + "/keepassxc";
#endif

QString suffix;
Expand Down