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