1
0
Fork 0
mirror of https://github.com/restic/restic.git synced 2025-03-09 00:00:02 +01:00

Add missing func GetCacheDir()

restic now compiles on windows
This commit is contained in:
Marcelo Pires 2015-03-21 00:43:09 +00:00
parent f0d160808c
commit 3c39a6050f

45
cache_windows.go Normal file
View file

@ -0,0 +1,45 @@
package restic
import (
"errors"
"fmt"
"os"
"path/filepath"
"github.com/restic/restic/debug"
)
// GetCacheDir returns the cache directory
func GetCacheDir() (string, error) {
AppData := os.Getenv("AppData")
if AppData == "" {
return "", errors.New("unable to locate cache directory")
}
cachedir := ""
if AppData != "" {
cachedir = filepath.Join(AppData, "restic")
}
fi, err := os.Stat(cachedir)
if os.IsNotExist(err) {
err = os.MkdirAll(cachedir, 0700)
if err != nil {
return "", err
}
fi, err = os.Stat(cachedir)
debug.Log("getCacheDir", "create cache dir %v", cachedir)
}
if err != nil {
return "", err
}
if !fi.IsDir() {
return "", fmt.Errorf("cache dir %v is not a directory", cachedir)
}
return cachedir, nil
}