mirror of
https://github.com/restic/restic.git
synced 2025-12-11 18:47:50 +00:00
cache: move to backend package
This commit is contained in:
28
internal/backend/cache/dir.go
vendored
Normal file
28
internal/backend/cache/dir.go
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user