-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
phoerious
merged 10 commits into
keepassxreboot:develop
from
jNullj:feat/switch-to-XDG_STATE_HOME-9738
Oct 23, 2023
Merged
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
31c7159
Change conf path XDG_CACHE_HOME to XDG_STATE_HOME
jNullj 134c56d
update docs for switch to XDG_STATE_HOME
jNullj b8bcf23
fix format
jNullj c5ca0bb
Migrate old conf file to new location on linux
jNullj 2eecf98
remove unnecessary condition
jNullj 0cd5ce4
Improve code readability
jNullj d77ef9d
Improve performance
jNullj 85a2b74
Improve code readability
jNullj 74c0f3d
Merge branch 'develop' into feat/switch-to-XDG_STATE_HOME-9738
jNullj bb9700d
Merge branch 'develop' into feat/switch-to-XDG_STATE_HOME-9738
jNullj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)) { | ||
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)); | ||
|
@@ -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")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Combine these two. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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