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

Conversation

jNullj
Copy link
Contributor

@jNullj jNullj commented Aug 18, 2023

Keepassxc saves application state at XDG_CACHE_HOME which can be cleared on some systems periodicly.
This is not desireable as app state like window size is not consistent when openning the app.
To avoid this, this PR commit is switching the path to XDG_STATE_HOME which is more fitting based on the freedesktop basedir spec, this will allow to prevent state file deletion as well.

Changes made based on how qt implements QStandardPaths (very similar to internal qt code)

Also added code to migrate old config files to new location and cleanup files from old location.

Fixes #9738

Screenshots

N/A

Testing strategy

Manually tested file changes in ~/.local/state and that migration from ~/.cache works.

Type of change

  • ✅ New feature (change that adds functionality)
  • ✅ Breaking change (causes existing functionality to change)
  • ✅ Documentation (non-code change)

Keepassxc saves application state at XDG_CACHE_HOME which can be cleared on some systems periodicly.
This is not desireable as app state like window size is not consistent when openning the app.
To avoid this this commit is switching the path to XDG_STATE_HOME which is more fitting based on the freedesktop basedir spec (https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html), this will allow to prevent state file deletion as well.

Solves keepassxreboot#9738
Copy link
Member

@phoerious phoerious left a comment

Choose a reason for hiding this comment

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

You should migrate existing settings from the old location.

@jNullj jNullj force-pushed the feat/switch-to-XDG_STATE_HOME-9738 branch from 9845079 to c5ca0bb Compare August 18, 2023 10:44
@jNullj jNullj marked this pull request as ready for review August 18, 2023 11:06
@jNullj jNullj requested a review from phoerious August 18, 2023 11:06
Comment on lines 479 to 487
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

Comment on lines 536 to 537
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

Only generate oldLocalConfigPath if the local config is missing and the old config path should be checked.
Before this commit oldLocalConfigPath would always get generated, while it won't be needed most of the time.
Comment on lines 480 to 481
QString oldLocalConfigPath;
oldLocalConfigPath = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + "/keepassxc";
Copy link
Member

Choose a reason for hiding this comment

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

You should not separate declaration/definition and assignment. Rest looks good.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 85a2b74

@jNullj jNullj requested a review from phoerious August 29, 2023 21:38
@phoerious phoerious added this to the v2.8.0 milestone Oct 23, 2023
@phoerious
Copy link
Member

Looks good now. Thanks for your patience.

@phoerious phoerious merged commit 509e218 into keepassxreboot:develop Oct 23, 2023
10 of 11 checks passed
pull bot pushed a commit to tigerwill90/keepassxc that referenced this pull request Oct 23, 2023
Keepassxc saves application state at XDG_CACHE_HOME which can be cleared on some systems periodicly.
This is not desireable as app state like window size is not consistent when openning the app.
To avoid this this commit is switching the path to XDG_STATE_HOME which is more fitting based on the freedesktop basedir spec (https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html), this will allow to prevent state file deletion as well.

Resolves keepassxreboot#9738
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider using XDG_STATE_HOME instead of cache folder for local config
2 participants