mirror of
https://github.com/octoleo/restic.git
synced 2024-11-26 06:46:34 +00:00
Add default cache location for Windows.
Primary place for Windows cache is %APPDATA%\restic. If that environment variable isn't set, we create a 'restic' folder in the 'temp' directory.
This commit is contained in:
parent
21ab5a488d
commit
8a2d7ff2bc
31
cache.go
31
cache.go
@ -6,6 +6,7 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/restic/restic/backend"
|
||||
@ -212,10 +213,40 @@ func getCacheDir() (string, error) {
|
||||
if dir := os.Getenv("RESTIC_CACHE"); dir != "" {
|
||||
return dir, nil
|
||||
}
|
||||
if runtime.GOOS == "windows" {
|
||||
return getWindowsCacheDir()
|
||||
}
|
||||
|
||||
return getXDGCacheDir()
|
||||
}
|
||||
|
||||
// getWindowsCacheDir will return %APPDATA%\restic or create
|
||||
// a folder in the temporary folder called "restic".
|
||||
func getWindowsCacheDir() (string, error) {
|
||||
cachedir := os.Getenv("APPDATA")
|
||||
if cachedir == "" {
|
||||
cachedir = os.TempDir()
|
||||
}
|
||||
cachedir = filepath.Join(cachedir, "restic")
|
||||
fi, err := os.Stat(cachedir)
|
||||
|
||||
if os.IsNotExist(err) {
|
||||
err = os.MkdirAll(cachedir, 0700)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if !fi.IsDir() {
|
||||
return "", fmt.Errorf("cache dir %v is not a directory", cachedir)
|
||||
}
|
||||
return cachedir, nil
|
||||
}
|
||||
|
||||
// getXDGCacheDir returns the cache directory according to XDG basedir spec, see
|
||||
// http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
|
||||
func getXDGCacheDir() (string, error) {
|
||||
|
Loading…
Reference in New Issue
Block a user