mirror of
https://github.com/rclone/rclone.git
synced 2024-11-07 09:04:52 +01:00
config: use os.UserCacheDir from go stdlib to find cache dir #6095
When this code was originally implemented os.UserCacheDir wasn't public so this used a copy of the code. This commit replaces that now out of date copy with a call to the now public stdlib function.
This commit is contained in:
parent
f1e4b7da7b
commit
27176cc6bb
@ -674,41 +674,11 @@ func Dump() error {
|
||||
}
|
||||
|
||||
// makeCacheDir returns a directory to use for caching.
|
||||
//
|
||||
// Code borrowed from go stdlib until it is made public
|
||||
func makeCacheDir() (dir string) {
|
||||
// Compute default location.
|
||||
switch runtime.GOOS {
|
||||
case "windows":
|
||||
dir = os.Getenv("LocalAppData")
|
||||
|
||||
case "darwin":
|
||||
dir = os.Getenv("HOME")
|
||||
if dir != "" {
|
||||
dir += "/Library/Caches"
|
||||
}
|
||||
|
||||
case "plan9":
|
||||
dir = os.Getenv("home")
|
||||
if dir != "" {
|
||||
// Plan 9 has no established per-user cache directory,
|
||||
// but $home/lib/xyz is the usual equivalent of $HOME/.xyz on Unix.
|
||||
dir += "/lib/cache"
|
||||
}
|
||||
|
||||
default: // Unix
|
||||
// https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
|
||||
dir = os.Getenv("XDG_CACHE_HOME")
|
||||
if dir == "" {
|
||||
dir = os.Getenv("HOME")
|
||||
if dir != "" {
|
||||
dir += "/.cache"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if no dir found then use TempDir - we will have a cachedir!
|
||||
if dir == "" {
|
||||
dir, err := os.UserCacheDir()
|
||||
if err != nil || dir == "" {
|
||||
fs.Debugf(nil, "Failed to find user cache dir, using temporary directory: %v", err)
|
||||
// if no dir found then use TempDir - we will have a cachedir!
|
||||
dir = os.TempDir()
|
||||
}
|
||||
return filepath.Join(dir, "rclone")
|
||||
|
Loading…
Reference in New Issue
Block a user