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"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"path"
|
"path"
|
||||||
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -45,7 +46,7 @@ const (
|
||||||
// Globals
|
// Globals
|
||||||
var (
|
var (
|
||||||
// Flags
|
// 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")
|
cacheDbPurge = fs.BoolP("cache-db-purge", "", false, "Purge the cache DB before")
|
||||||
cacheChunkSize = fs.StringP("cache-chunk-size", "", DefCacheChunkSize, "The size of a chunk")
|
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")
|
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)
|
f.rateLimiter = rate.NewLimiter(rate.Limit(float64(*cacheRps)), f.totalWorkers)
|
||||||
|
|
||||||
dbPath := *cacheDbPath
|
dbPath := *cacheDbPath
|
||||||
if path.Ext(dbPath) != "" {
|
if filepath.Ext(dbPath) != "" {
|
||||||
dbPath = path.Dir(dbPath)
|
dbPath = filepath.Dir(dbPath)
|
||||||
}
|
}
|
||||||
err = os.MkdirAll(dbPath, os.ModePerm)
|
err = os.MkdirAll(dbPath, os.ModePerm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "failed to create cache directory %v", dbPath)
|
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)
|
fs.Infof(name, "Storage DB path: %v", dbPath)
|
||||||
f.cache = GetPersistent(dbPath, *cacheDbPurge)
|
f.cache = GetPersistent(dbPath, *cacheDbPurge)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
3
cache/cache_internal_test.go
vendored
3
cache/cache_internal_test.go
vendored
|
@ -9,6 +9,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"path"
|
"path"
|
||||||
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -42,7 +43,7 @@ func TestInternalInit(t *testing.T) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
// delete the default path
|
// 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)
|
boltDb = cache.GetPersistent(dbPath, true)
|
||||||
fstest.Initialise()
|
fstest.Initialise()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue