mirror of
https://github.com/rclone/rclone.git
synced 2025-04-16 16:18:52 +08:00
lib/kv: accept dir argument instead of internally using config.GetCacheDir()
This change makes it possible to use lib/kv for other purposes while allowing to store the db in a place more accessible for the user
This commit is contained in:
parent
0b9671313b
commit
329de0a2f6
@ -14,6 +14,7 @@ import (
|
||||
|
||||
"github.com/rclone/rclone/fs"
|
||||
"github.com/rclone/rclone/fs/cache"
|
||||
"github.com/rclone/rclone/fs/config"
|
||||
"github.com/rclone/rclone/fs/config/configmap"
|
||||
"github.com/rclone/rclone/fs/config/configstruct"
|
||||
"github.com/rclone/rclone/fs/fspath"
|
||||
@ -157,7 +158,7 @@ func NewFs(ctx context.Context, fsname, rpath string, cmap configmap.Mapper) (fs
|
||||
|
||||
if f.opt.MaxAge > 0 {
|
||||
gob.Register(hashRecord{})
|
||||
db, err := kv.Start(ctx, "hasher", f.Fs)
|
||||
db, err := kv.Start(ctx, "hasher", config.GetCacheDir(), f.Fs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/rclone/rclone/fs"
|
||||
"github.com/rclone/rclone/fs/config"
|
||||
"github.com/rclone/rclone/lib/encoder"
|
||||
"go.etcd.io/bbolt"
|
||||
)
|
||||
@ -66,14 +65,12 @@ func makeName(facility string, f fs.Fs) string {
|
||||
}
|
||||
|
||||
// Start a new key-value database
|
||||
func Start(ctx context.Context, facility string, f fs.Fs) (*DB, error) {
|
||||
func Start(ctx context.Context, facility string, dir string, f fs.Fs) (*DB, error) {
|
||||
dbMut.Lock()
|
||||
defer dbMut.Unlock()
|
||||
if db := lockedGet(facility, f); db != nil {
|
||||
return db, nil
|
||||
}
|
||||
|
||||
dir := filepath.Join(config.GetCacheDir(), "kv")
|
||||
if err := os.MkdirAll(dir, dbDirMode); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/rclone/rclone/fs/config"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@ -22,7 +23,7 @@ func TestKvConcurrency(t *testing.T) {
|
||||
wg.Add(threadNum)
|
||||
for i := range threadNum {
|
||||
go func(i int) {
|
||||
db, err := Start(ctx, "test", nil)
|
||||
db, err := Start(ctx, "test", config.GetCacheDir(), nil)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, db)
|
||||
results[i] = db
|
||||
@ -57,7 +58,7 @@ func TestKvExit(t *testing.T) {
|
||||
for i := range dbNum {
|
||||
facility := fmt.Sprintf("test-%d", i)
|
||||
for j := 0; j <= i; j++ {
|
||||
db, err := Start(ctx, facility, nil)
|
||||
db, err := Start(ctx, facility, config.GetCacheDir(), nil)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, db)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user