2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-22 21:05:10 +00:00

Merge pull request #2425 from thiell/restic_cache_dir_env

Add support for $RESTIC_CACHE_DIR
This commit is contained in:
rawtaz 2019-11-20 21:18:57 +01:00 committed by GitHub
commit 41fe9318b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 5 deletions

View File

@ -376,9 +376,10 @@ OS-specific cache folder:
* macOS: ``~/Library/Caches/restic``
* Windows: ``%LOCALAPPDATA%/restic``
The command line parameter ``--cache-dir`` can each be used to override the
default cache location. The parameter ``--no-cache`` disables the cache
entirely. In this case, all data is loaded from the repo.
The command line parameter ``--cache-dir`` or the environment variable
``$RESTIC_CACHE_DIR`` can be used to override the default cache location. The
parameter ``--no-cache`` disables the cache entirely. In this case, all data
is loaded from the repo.
The cache is ephemeral: When a file cannot be read from the cache, it is loaded
from the repository.

View File

@ -12,17 +12,21 @@ import (
// xdgCacheDir returns the cache directory according to XDG basedir spec, see
// http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
// unless RESTIC_CACHE_DIR is defined
func xdgCacheDir() (string, error) {
cachedir := os.Getenv("RESTIC_CACHE_DIR")
xdgcache := os.Getenv("XDG_CACHE_HOME")
home := os.Getenv("HOME")
if xdgcache != "" {
if cachedir != "" {
return cachedir, nil
} else if xdgcache != "" {
return filepath.Join(xdgcache, "restic"), nil
} else if home != "" {
return filepath.Join(home, ".cache", "restic"), nil
}
return "", errors.New("unable to locate cache directory (XDG_CACHE_HOME and HOME unset)")
return "", errors.New("unable to locate cache directory (RESTIC_CACHE_DIR, XDG_CACHE_HOME and HOME unset)")
}
// windowsCacheDir returns the cache directory for Windows.