Merge pull request #1454 from restic/fix-cache-dir

Fix cache dir detection
This commit is contained in:
Alexander Neumann 2017-11-29 18:43:07 +01:00
commit 410efe0694
2 changed files with 11 additions and 2 deletions

View File

@ -86,6 +86,9 @@ func writeCachedirTag(dir string) error {
func New(id string, basedir string) (c *Cache, err error) { func New(id string, basedir string) (c *Cache, err error) {
if basedir == "" { if basedir == "" {
basedir, err = DefaultDir() basedir, err = DefaultDir()
if err != nil {
return nil, err
}
} }
err = mkdirCacheDir(basedir) err = mkdirCacheDir(basedir)

10
internal/cache/dir.go vendored
View File

@ -56,10 +56,16 @@ func DefaultDir() (cachedir string, err error) {
cachedir, err = darwinCacheDir() cachedir, err = darwinCacheDir()
case "windows": case "windows":
cachedir, err = windowsCacheDir() cachedir, err = windowsCacheDir()
default:
// Default to XDG for Linux and any other OSes.
cachedir, err = xdgCacheDir()
} }
// Default to XDG for Linux and any other OSes. if err != nil {
return xdgCacheDir() return "", err
}
return cachedir, nil
} }
func mkdirCacheDir(cachedir string) error { func mkdirCacheDir(cachedir string) error {