mirror of
https://github.com/rclone/rclone
synced 2024-12-29 22:26:24 +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.
|
// makeCacheDir returns a directory to use for caching.
|
||||||
//
|
|
||||||
// Code borrowed from go stdlib until it is made public
|
|
||||||
func makeCacheDir() (dir string) {
|
func makeCacheDir() (dir string) {
|
||||||
// Compute default location.
|
dir, err := os.UserCacheDir()
|
||||||
switch runtime.GOOS {
|
if err != nil || dir == "" {
|
||||||
case "windows":
|
fs.Debugf(nil, "Failed to find user cache dir, using temporary directory: %v", err)
|
||||||
dir = os.Getenv("LocalAppData")
|
// if no dir found then use TempDir - we will have a cachedir!
|
||||||
|
|
||||||
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 = os.TempDir()
|
dir = os.TempDir()
|
||||||
}
|
}
|
||||||
return filepath.Join(dir, "rclone")
|
return filepath.Join(dir, "rclone")
|
||||||
|
Loading…
Reference in New Issue
Block a user