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:
parent
f0d160808c
commit
3c39a6050f
1 changed files with 45 additions and 0 deletions
45
cache_windows.go
Normal file
45
cache_windows.go
Normal 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
|
||||
}
|
Loading…
Add table
Reference in a new issue