mirror of
https://github.com/octoleo/restic.git
synced 2024-11-22 21:05:10 +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"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/restic/restic/backend"
|
"github.com/restic/restic/backend"
|
||||||
@ -212,10 +213,40 @@ func getCacheDir() (string, error) {
|
|||||||
if dir := os.Getenv("RESTIC_CACHE"); dir != "" {
|
if dir := os.Getenv("RESTIC_CACHE"); dir != "" {
|
||||||
return dir, nil
|
return dir, nil
|
||||||
}
|
}
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
return getWindowsCacheDir()
|
||||||
|
}
|
||||||
|
|
||||||
return getXDGCacheDir()
|
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
|
// getXDGCacheDir returns the cache directory according to XDG basedir spec, see
|
||||||
// http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
|
// http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
|
||||||
func getXDGCacheDir() (string, error) {
|
func getXDGCacheDir() (string, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user