mirror of
https://github.com/octoleo/restic.git
synced 2024-11-22 21:05:10 +00:00
Implement per-repository cache
This commit is contained in:
parent
f69a39cff5
commit
e1fc17aeb1
@ -53,7 +53,7 @@ func NewArchiver(s Server) (*Archiver, error) {
|
||||
arch.m = NewMap()
|
||||
|
||||
// init cache
|
||||
arch.c, err = NewCache()
|
||||
arch.c, err = NewCache(s)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
23
cache.go
23
cache.go
@ -7,22 +7,29 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/restic/restic/backend"
|
||||
"github.com/restic/restic/debug"
|
||||
)
|
||||
|
||||
// for testing
|
||||
var getCacheDir = GetCacheDir
|
||||
|
||||
type Cache struct {
|
||||
base string
|
||||
}
|
||||
|
||||
func NewCache() (*Cache, error) {
|
||||
dir, err := getCacheDir()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
func NewCache(be backend.IDer) (c *Cache, err error) {
|
||||
// try to get explicit cache dir from environment
|
||||
dir := os.Getenv("RESTIC_CACHE")
|
||||
|
||||
// otherwise try OS specific default
|
||||
if dir == "" {
|
||||
dir, err = GetCacheDir()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return &Cache{base: dir}, nil
|
||||
basedir := filepath.Join(dir, be.ID().String())
|
||||
debug.Log("Cache.New", "opened cache at %v", basedir)
|
||||
|
||||
return &Cache{base: basedir}, nil
|
||||
}
|
||||
|
||||
func (c *Cache) Has(t backend.Type, subtype string, id backend.ID) (bool, error) {
|
||||
|
@ -42,7 +42,7 @@ func (cmd CmdCache) Execute(args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
cache, err := restic.NewCache()
|
||||
cache, err := restic.NewCache(s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ func (cmd CmdInit) Execute(args []string) error {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Printf("created restic backend at %s\n", opts.Repo)
|
||||
fmt.Printf("created restic backend %v at %s\n", s.ID().Str(), opts.Repo)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/restic/restic"
|
||||
@ -22,7 +23,12 @@ func setupBackend(t testing.TB) restic.Server {
|
||||
tempdir, err := ioutil.TempDir(*testTempDir, "restic-test-")
|
||||
ok(t, err)
|
||||
|
||||
b, err := backend.CreateLocal(tempdir)
|
||||
// create repository below temp dir
|
||||
b, err := backend.CreateLocal(filepath.Join(tempdir, "repo"))
|
||||
ok(t, err)
|
||||
|
||||
// set cache dir
|
||||
err = os.Setenv("RESTIC_CACHE", filepath.Join(tempdir, "cache"))
|
||||
ok(t, err)
|
||||
|
||||
return restic.NewServer(b)
|
||||
|
Loading…
Reference in New Issue
Block a user