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

Attempt to use user configured dirs for caching #153

Merged
merged 2 commits into from Mar 19, 2024

Conversation

williammartin
Copy link
Member

Description

This change supports XDG_CACHE_DIR from the xdg spec.

A minor concern I have about moving this out of /tmp is that we might slowly fill up the disk. In practice I'm not sure that this is a big issue.

Copy link
Contributor

@andyfeller andyfeller left a comment

Choose a reason for hiding this comment

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

Not going to be a problem with this review, but cli/cli has some hardcoded references to the legacy cache location

pkg/config/config.go Outdated Show resolved Hide resolved
Comment on lines +293 to +305
if a := os.Getenv(xdgCacheHome); a != "" {
return filepath.Join(a, "gh")
} else if b := os.Getenv(localAppData); runtime.GOOS == "windows" && b != "" {
return filepath.Join(b, "GitHub CLI")
} else if c, err := os.UserHomeDir(); err == nil {
return filepath.Join(c, ".cache", "gh")
} else {
// Note that this has a minor security issue because /tmp is world-writeable.
// As such, it is possible for other users on a shared system to overwrite cached data.
// The practical risk of this is low, but it's worth calling out as a risk.
// I've included this here for backwards compatibility but we should consider removing it.
return filepath.Join(os.TempDir(), "gh-cli-cache")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think there is a problem, but I was wondering how cli/cli would handle this directory if it didn't exist because someone deleted it manually or used gh config clear-cache but I realized that would be an issue regardless where the directory was.

Co-authored-by: Andy Feller <andyfeller@github.com>
@williammartin
Copy link
Member Author

Not going to be a problem with this review, but cli/cli has some hardcoded references to the legacy cache location

Excellent call out. Let's make sure we resolve that when we bump!

@williammartin williammartin merged commit 288843f into trunk Mar 19, 2024
10 checks passed
@williammartin williammartin deleted the wm/support-xdg-cache-home branch March 19, 2024 20:13
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.

None yet

2 participants