Skip to content

Attempt to use user configured dirs for caching - #153

Merged
williammartin merged 2 commits into
trunkfrom
wm/support-xdg-cache-home
Mar 19, 2024
Merged

williammartin merged 2 commits into
trunkfrom
wm/support-xdg-cache-home

Conversation

@williammartin

Copy link
Copy Markdown
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.

@williammartin
williammartin force-pushed the wm/support-xdg-cache-home branch from 33d2eba to dd8374e Compare March 19, 2024 17:28

@andyfeller andyfeller left a comment

Copy link
Copy Markdown
Contributor

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

Comment thread pkg/config/config.go Outdated
Comment thread pkg/config/config.go
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
Copy Markdown
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 <[email protected]>
@williammartin

Copy link
Copy Markdown
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!

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.

2 participants