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

Use the XDG Basedir Spec for the cache #208

Closed
wants to merge 3 commits into from
Closed

Use the XDG Basedir Spec for the cache #208

wants to merge 3 commits into from

Conversation

WhyNotHugo
Copy link

Currently, for caching data, a new directory is created in the current user's home directory. This is bad practice (if all apps just dump files into the user's home, it becomes somewhat unmaintainable).

The XDG Basedir Specification covers this pretty neatly; the cache directory for all applications is configurable via the XDG_CACHE_HOME variable, and falls back to ~/.cache if unset.

This PR makes the cache for all applications live in one single location, rather that littering the user's home.

Fixes #205

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Currently, for caching data, a new directory is created in the current
user's home directory. This is bad practice (if all apps just dump files
into the user's home, it becomes somewhat unmaintainable).

The XDG Basedir Specification covers this pretty neatly; the cache
directory for all applications is configurable via the `XDG_CACHE_HOME`
variable, and falls back to `~/.cache` if unset.

This changeset makes the cache for all applications live in one single
location, rather that littering the user's home.
@samuelkarp
Copy link
Contributor

Hello @WhyNotHugo, thanks for sending this pull request! There are a few things that I think need to be addressed before we can merge a change like this:

  • This change as it stands is not backwards-compatible with installations where files are already present in ~/.ecr. The credential helper should either continue to use those files when present, or handle migrating them to the new location without intervention.
  • The XDG Base Directory Specification is widely used on Linux, but not so on other operating systems. The credential helper supports Linux, Windows, and macOS, and should work with the appropriate location for each. See os: add func UserCacheDir() string golang/go#22536 for a discussion of the correct cache location, and proposal: os: add UserConfigDir golang/go#29960 for a discussion of config locations. The code as-is doesn't use the correct locations for Windows or macOS, but I would prefer to not migrate twice; we should either gate this change to be Linux-only or also move to the correct locations for Windows and macOS at the same time. Go 1.11 added os.UserCacheDir; I would be okay dropping support for Go 1.10 in order to use that function.
  • This change affects the log file location, which is documented in the README; that needs to be updated.
  • Since the file is moving, I think the new location should be documented in the README and the manual page.

If you're willing and able to make these changes, I'd be happy to move forward with this PR. If you're not, I'd be happy to leave this open and then use it as the base of a change that does address the other concerns.

@WhyNotHugo
Copy link
Author

WhyNotHugo commented Apr 20, 2020 via email

Hugo Osvaldo Barrera added 2 commits May 17, 2020 20:31
This returns the per-platorm cache dir, since the XDG-Basedir is
*nix-specific (except macOS?).
@WhyNotHugo
Copy link
Author

[Note: Still have pending moving existing files]

Since the file is moving, I think the new location should be documented in the README and the manual page.

There seems to be no mention on the manual page right now. Should I add a FILES section at the bottom?

@samuelkarp
Copy link
Contributor

There seems to be no mention on the manual page right now. Should I add a FILES section at the bottom?

You're right! It would be nice to add a FILES section, but I won't block accepting this PR on that change.

@@ -19,5 +19,7 @@ func GetCacheDir() string {
if cacheDir := os.Getenv("AWS_ECR_CACHE_DIR"); cacheDir != "" {
return cacheDir
}
return "~/.ecr"
dir, _ := os.UserCacheDir()
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's not ignore the error here.

Suggested change
dir, _ := os.UserCacheDir()
dir, err := os.UserCacheDir()
if err != nil {
return "~/.ecr"
}

@@ -214,7 +214,8 @@ There is no need to use `docker login` or `docker logout`.

## Troubleshooting

Logs from the Amazon ECR Docker Credential Helper are stored in `~/.ecr/log`.
Logs from the Amazon ECR Docker Credential Helper are stored inside you cache
files directory (e.g.: `~/.cache/ecr/log` on *nix).
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's either link to the Go documentation or describe the specific locations for Linux, Windows, and Mac.

@samuelkarp
Copy link
Contributor

Hey @WhyNotHugo! I've taken your commits and adjusted them to add fall-back behavior to ~/.ecr when it's present so that people upgrading can continue to use the existing cache. The new PR can be found here: #250.

@samuelkarp samuelkarp closed this Dec 22, 2020
@WhyNotHugo
Copy link
Author

WhyNotHugo commented Dec 24, 2020

Sorry, I never got around to finishing those changes (plus, my go is super rusty).

Happy that it's being picked up. I'm of course perfectly fine with the code being reused!

Happy holidays!

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.

Respect XDG Base Directory specification for cache files
2 participants