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

cmd: Fix paths when using an env file #4296

Merged
merged 2 commits into from
Aug 20, 2021

Conversation

pascal-zarrad
Copy link
Contributor

Description

Fix the behaviour of the environment variables XDG_DATA_HOME and XDG_CONFIG_HOME when supplied through an env file to match the expected one.

For further information, check #4273

Related Issues

Resolves #4273

Testing

  • Caddy should create its data and config directories and files at the common location as always when no env file is specified using --envfile.
    • For example: /home/user/.local/share/caddy/<files and/or folders>
  • When an env file is specified using --envfile, Caddy should use the environment variables XDG_DATA_HOME and XDG_CONFIG_HOME from the env file instead (instead) of the system ones. This should cause Caddy to create its files/directories at the location specified in the env file.
    • Example: Instead of /home/user/.local/share/caddy/autosave.json Caddy now uses /home/user/caddydata/caddy/autosave.json, when XDG_CONFIG_HOME was set to /home/user/caddydata in the env file.

@CLAassistant
Copy link

CLAassistant commented Aug 20, 2021

CLA assistant check
All committers have signed the CLA.

@francislavoie francislavoie added the under review 🧐 Review is pending before merging label Aug 20, 2021
@francislavoie francislavoie added this to the v2.4.4 milestone Aug 20, 2021
@francislavoie francislavoie changed the title Fix paths when using an env file cmd: Fix paths when using an env file Aug 20, 2021
@francislavoie francislavoie requested a review from mholt August 20, 2021 16:20
francislavoie
francislavoie previously approved these changes Aug 20, 2021
Copy link
Member

@mholt mholt left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. (Sorry for how long it's taking me to get around to this issue.)

I'm very sensitive about adding new exported identifiers, and in this case I think we can avoid it. The function is only called in one place, so I think it'd be fair to just move that logic directly into the loadEnvFromFile() function, or, if you still want a separate function, move it next to loadEnvFromFile() and leave it unexported. (I don't think it needs to be a separate function though, personally.)

That sound alright?

@pascal-zarrad pascal-zarrad force-pushed the feature/fix-env-paths branch from e6fc152 to 57bc70b Compare August 20, 2021 17:47
@francislavoie francislavoie requested a review from mholt August 20, 2021 17:58
@pascal-zarrad
Copy link
Contributor Author

I agree that exporting this function isn't really necessary. Exporting it brings the risk of someone using it at a wrong spot in the future.

The logic has been moved to loadEnvFromFile(). I also brought the branch up to date.

@mholt
Copy link
Member

mholt commented Aug 20, 2021

Much better - thanks so much!

@mholt mholt merged commit ce5a45d into caddyserver:master Aug 20, 2021
@pascal-zarrad pascal-zarrad deleted the feature/fix-env-paths branch August 20, 2021 22:41
@mholt mholt removed the under review 🧐 Review is pending before merging label Jan 6, 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.

Caddy environment files do not affect config & data paths
4 participants