Skip to content

Use XDG Base Directory variables when creating the base installation directory - #1081

Merged
itowlson merged 2 commits into
vscode-kubernetes-tools:masterfrom
hyperupcall:xdg-vs-kubernetes
Jun 14, 2022
Merged

itowlson merged 2 commits into
vscode-kubernetes-tools:masterfrom
hyperupcall:xdg-vs-kubernetes

Conversation

@hyperupcall

Copy link
Copy Markdown
Contributor

The XDG Base Directory Specification specifies various user directories for applications to store data. There are a lot of good reasons to support this, and this PR adds support in a backwards-compatible way

  • This PR adheres to the spec by creating the vs-kubernetes directory in ~/.local/state, but only if a directory has not been created at ~/.vs-kubernetes and the current platform is Linux
    • In the case where we can follow the XDG Base Directory Specification, users can customize where the vs-kubernetes directory is created with the XDG_STATE_HOME variable. If the env var is empty or if it's a relative path (as per the spec), the default of ~/.local/state is used

@lstocchi lstocchi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I didn't know the XDG base directory specification so thanks for this. Very interesting.

The only concern I have is to use a different default path when the user is not adhering to this specification. See comment below.

The other aspect is we need to update the README otherwise nobody would know that the extension leverages it.

BTW I'm also open at accepting all changes, I would wait to hear from @itowlson


let xdgStateHome = process.env.XDG_STATE_HOME || ``;
if (xdgStateHome[0] !== `/`) {
xdgStateHome = path.join(os.homedir(), `.local/state`);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think it would be better to keep the default path as it is now path.join(shell.home(), '.vs-kubernetes'). If one deletes the existing folder for some reason and then it is recreated somewhere else the user doesn't get what's going on.
Then by doing it we would only have two different cases 1) user who doesn't use XDG specification 2) users who use it... and we don't need to remember that old linux/windows/mac users uses .vs-kubernetes folder, new linux users use .local/state and people who use xdg specification may have their custom folder.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah, so if I understand correctly, your point is that it would be less confusing to users if there is an explicit "opt-in" to the "XDG Base Dir Specification". So for example, we would only follow the spec if XDG_STATE_HOME is set explicitly?

I feel like doing it this way would be more counterintuitive for the user and we would realize less gains from attempting to use the spec in the first place. Mostly because most users expect things to go in ~/.local/state, ~/.config, etc. automatically. The spirit of the spec is that this should be automatic behavior, and if we have to check if XDG_STATE_HOME is set (which very few people actually do), then most people wouldn't be affected by this benefit (and in this case i would rather the PR not be merged since its an incomplete solution). There is also the issue of potentially having to do more of these checks for every new XDG variable used (assuming consistency is valued here) - whereas currently we only ever need to do existsSync(~/.vs-kubernetes) once

I think your statement about the end-user confusion when deleting ~/.vs-kubernetes and it being recreated somewhere else is definitely valid, and I believe your mention of updating the README to address this PR in general can address that. Maybe we can say somewhere in the README along the lines of "the extension will follow the XDG Base Directory Specification appropriately (defaulting to writing config and other files in ~/.local/state/vs-kubernetes), but only if the legacy directory of ~/.vs-kubernetes does not exist". That way, if the user searches for "config" or ".vs-kubernetes" in the docs, they know what's up right away

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I like "use the legacy directory if it exists, otherwise use the XDG directory." Seems like a nice pragmatic solution.

@itowlson itowlson left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good to me - thanks! @lstocchi you okay with these changes?

@itowlson

Copy link
Copy Markdown
Collaborator

@hyperupcall Could you sign off for the DCO please? Thanks!

Signed-off-by: Edwin Kofler <edwin@kofler.dev>
Prevents user confusion since the directory might be re-createad in the
newer location if the older location is removed

Signed-off-by: Edwin Kofler <edwin@kofler.dev>
@hyperupcall

Copy link
Copy Markdown
Contributor Author

DCO done! 👍 Also as mentioned before, I also updated the readme to explicitly document this to prevent any user confusion :)

@itowlson
itowlson merged commit 4cda829 into vscode-kubernetes-tools:master Jun 14, 2022
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