2017-06-10 11:10:08 +00:00
|
|
|
package cache
|
|
|
|
|
|
|
|
import (
|
2020-02-27 22:03:22 +00:00
|
|
|
"fmt"
|
2017-06-10 11:10:08 +00:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
)
|
|
|
|
|
2021-08-08 17:30:07 +00:00
|
|
|
// EnvDir return $RESTIC_CACHE_DIR env
|
|
|
|
func EnvDir() string {
|
|
|
|
return os.Getenv("RESTIC_CACHE_DIR")
|
|
|
|
}
|
|
|
|
|
2020-02-27 22:03:22 +00:00
|
|
|
// 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) {
|
2021-08-08 17:30:07 +00:00
|
|
|
cachedir = EnvDir()
|
2019-09-26 22:48:52 +00:00
|
|
|
if cachedir != "" {
|
|
|
|
return cachedir, nil
|
2017-06-10 11:10:08 +00:00
|
|
|
}
|
|
|
|
|
2020-02-27 22:03:22 +00:00
|
|
|
cachedir, err = os.UserCacheDir()
|
2017-11-20 05:11:18 +00:00
|
|
|
if err != nil {
|
2020-02-27 22:03:22 +00:00
|
|
|
return "", fmt.Errorf("unable to locate cache directory: %v", err)
|
2017-11-20 05:11:18 +00:00
|
|
|
}
|
|
|
|
|
2020-02-27 22:03:22 +00:00
|
|
|
return filepath.Join(cachedir, "restic"), nil
|
2017-11-20 20:58:38 +00:00
|
|
|
}
|