forked from TrueCloudLab/rclone
cache: use fs.CacheDir to make the default directory for the cache
NB this changes the default dir for the cache
This commit is contained in:
parent
af50f31f7d
commit
f80f7a0509
2 changed files with 7 additions and 5 deletions
9
cache/cache.go
vendored
9
cache/cache.go
vendored
|
@ -6,6 +6,7 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
|
@ -45,7 +46,7 @@ const (
|
|||
// Globals
|
||||
var (
|
||||
// Flags
|
||||
cacheDbPath = fs.StringP("cache-db-path", "", path.Join(path.Dir(fs.ConfigPath), "cache"), "Directory to cache DB")
|
||||
cacheDbPath = fs.StringP("cache-db-path", "", filepath.Join(fs.CacheDir, "cache-backend"), "Directory to cache DB")
|
||||
cacheDbPurge = fs.BoolP("cache-db-purge", "", false, "Purge the cache DB before")
|
||||
cacheChunkSize = fs.StringP("cache-chunk-size", "", DefCacheChunkSize, "The size of a chunk")
|
||||
cacheInfoAge = fs.StringP("cache-info-age", "", DefCacheInfoAge, "How much time should object info be stored in cache")
|
||||
|
@ -313,15 +314,15 @@ func NewFs(name, rpath string) (fs.Fs, error) {
|
|||
f.rateLimiter = rate.NewLimiter(rate.Limit(float64(*cacheRps)), f.totalWorkers)
|
||||
|
||||
dbPath := *cacheDbPath
|
||||
if path.Ext(dbPath) != "" {
|
||||
dbPath = path.Dir(dbPath)
|
||||
if filepath.Ext(dbPath) != "" {
|
||||
dbPath = filepath.Dir(dbPath)
|
||||
}
|
||||
err = os.MkdirAll(dbPath, os.ModePerm)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to create cache directory %v", dbPath)
|
||||
}
|
||||
|
||||
dbPath = path.Join(dbPath, name+".db")
|
||||
dbPath = filepath.Join(dbPath, name+".db")
|
||||
fs.Infof(name, "Storage DB path: %v", dbPath)
|
||||
f.cache = GetPersistent(dbPath, *cacheDbPurge)
|
||||
if err != nil {
|
||||
|
|
3
cache/cache_internal_test.go
vendored
3
cache/cache_internal_test.go
vendored
|
@ -9,6 +9,7 @@ import (
|
|||
"io/ioutil"
|
||||
"math/rand"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"sync"
|
||||
"testing"
|
||||
|
@ -42,7 +43,7 @@ func TestInternalInit(t *testing.T) {
|
|||
var err error
|
||||
|
||||
// delete the default path
|
||||
dbPath := path.Join(path.Dir(fs.ConfigPath), "cache", *RemoteName+".db")
|
||||
dbPath := filepath.Join(fs.CacheDir, "cache-backend", *RemoteName+".db")
|
||||
boltDb = cache.GetPersistent(dbPath, true)
|
||||
fstest.Initialise()
|
||||
|
||||
|
|
Loading…
Reference in a new issue