mirror of
https://github.com/octoleo/restic.git
synced 2024-11-25 22:27:35 +00:00
95eb859b54
Fix #3382: restic check doesn't obey the RESTIC_CACHE_DIR environment variable
29 lines
575 B
Go
29 lines
575 B
Go
package cache
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
// EnvDir return $RESTIC_CACHE_DIR env
|
|
func EnvDir() string {
|
|
return os.Getenv("RESTIC_CACHE_DIR")
|
|
}
|
|
|
|
// DefaultDir returns $RESTIC_CACHE_DIR, or the default cache directory
|
|
// for the current OS if that variable is not set.
|
|
func DefaultDir() (cachedir string, err error) {
|
|
cachedir = EnvDir()
|
|
if cachedir != "" {
|
|
return cachedir, nil
|
|
}
|
|
|
|
cachedir, err = os.UserCacheDir()
|
|
if err != nil {
|
|
return "", fmt.Errorf("unable to locate cache directory: %v", err)
|
|
}
|
|
|
|
return filepath.Join(cachedir, "restic"), nil
|
|
}
|