Skip to content

Add support for XDG_STATE_HOME#3717

Merged
samcoe merged 3 commits intotrunkfrom
xdg-state-2
Jun 1, 2021
Merged

Add support for XDG_STATE_HOME#3717
samcoe merged 3 commits intotrunkfrom
xdg-state-2

Conversation

@samcoe
Copy link
Contributor

@samcoe samcoe commented May 25, 2021

This PR adds support for the XDG_STATE_HOME environment variable. If present we will store the state.yml file at the path provided, if one already exists in the old config location we will try to migrate it to the new path. If the environment variable is not present then behavior will remain the same and the config directory will continue to be used to store state.yml.

cc #2470
cc #554

@samcoe samcoe self-assigned this May 25, 2021
if path := os.Getenv(XDG_STATE_HOME); path != "" {
path = filepath.Join(path, "gh")
if _, err := os.Stat(path); errors.Is(err, os.ErrNotExist) {
_ = os.MkdirAll(path, 0755)
Copy link
Contributor

Choose a reason for hiding this comment

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

This MkdirAll doesn't look like it's necessary here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Originally I didn't have it in there, but in the scenario where XDG_STATE_HOME is specified and there is no previous state.yml file then XDG_STATE_HOME/gh does not get created and the code that writes the state file does not create the directory so writing the state file will fail.

@samcoe samcoe marked this pull request as ready for review May 26, 2021 16:51
@samcoe samcoe requested review from a team and removed request for a team May 27, 2021 12:34
Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

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

Looks good!

I still think that the fallback path for application state should be LocalAppData on Windows instead of AppData, but I won't be too bummed about it even if it stays like this.

if path := os.Getenv(XDG_STATE_HOME); path != "" {
path = filepath.Join(path, "gh")
if !dirExists(path) {
_ = os.MkdirAll(path, 0755)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this mkdir necessary since migrateFile does it internally? It feels weird that just reading StateDir creates a filesystem entry even if no migration is happening

@samcoe samcoe merged commit e65d956 into trunk Jun 1, 2021
@samcoe samcoe deleted the xdg-state-2 branch June 1, 2021 19:57
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.

3 participants