forked from TrueCloudLab/rclone
fs/cache: add PutErr to add an fs.Fs with an fs.ErrorIsFile error to the cache
This commit is contained in:
parent
e3f6f68885
commit
5994fcfed8
2 changed files with 37 additions and 4 deletions
11
fs/cache/cache.go
vendored
11
fs/cache/cache.go
vendored
|
@ -168,14 +168,19 @@ func GetArr(ctx context.Context, fsStrings []string) (f []fs.Fs, err error) {
|
||||||
return fArr, nil
|
return fArr, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Put puts an fs.Fs named fsString into the cache
|
// PutErr puts an fs.Fs named fsString into the cache with err
|
||||||
func Put(fsString string, f fs.Fs) {
|
func PutErr(fsString string, f fs.Fs, err error) {
|
||||||
createOnFirstUse()
|
createOnFirstUse()
|
||||||
canonicalName := fs.ConfigString(f)
|
canonicalName := fs.ConfigString(f)
|
||||||
c.Put(canonicalName, f)
|
c.PutErr(canonicalName, f, err)
|
||||||
addMapping(fsString, canonicalName)
|
addMapping(fsString, canonicalName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Put puts an fs.Fs named fsString into the cache
|
||||||
|
func Put(fsString string, f fs.Fs) {
|
||||||
|
PutErr(fsString, f, nil)
|
||||||
|
}
|
||||||
|
|
||||||
// ClearConfig deletes all entries which were based on the config name passed in
|
// ClearConfig deletes all entries which were based on the config name passed in
|
||||||
//
|
//
|
||||||
// Returns number of entries deleted
|
// Returns number of entries deleted
|
||||||
|
|
30
fs/cache/cache_test.go
vendored
30
fs/cache/cache_test.go
vendored
|
@ -116,6 +116,35 @@ func TestGetError(t *testing.T) {
|
||||||
assert.Equal(t, 0, Entries())
|
assert.Equal(t, 0, Entries())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPutErr(t *testing.T) {
|
||||||
|
create := mockNewFs(t)
|
||||||
|
|
||||||
|
f, err := mockfs.NewFs(context.Background(), "mock", "", nil)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
assert.Equal(t, 0, Entries())
|
||||||
|
|
||||||
|
PutErr("mock:file.txt", f, fs.ErrorIsFile)
|
||||||
|
|
||||||
|
assert.Equal(t, 1, Entries())
|
||||||
|
|
||||||
|
fNew, err := GetFn(context.Background(), "mock:file.txt", create)
|
||||||
|
require.Equal(t, fs.ErrorIsFile, err)
|
||||||
|
require.Equal(t, f, fNew)
|
||||||
|
|
||||||
|
assert.Equal(t, 1, Entries())
|
||||||
|
|
||||||
|
// Check canonicalisation
|
||||||
|
|
||||||
|
PutErr("mock:/file.txt", f, fs.ErrorIsFile)
|
||||||
|
|
||||||
|
fNew, err = GetFn(context.Background(), "mock:/file.txt", create)
|
||||||
|
require.Equal(t, fs.ErrorIsFile, err)
|
||||||
|
require.Equal(t, f, fNew)
|
||||||
|
|
||||||
|
assert.Equal(t, 1, Entries())
|
||||||
|
}
|
||||||
|
|
||||||
func TestPut(t *testing.T) {
|
func TestPut(t *testing.T) {
|
||||||
create := mockNewFs(t)
|
create := mockNewFs(t)
|
||||||
|
|
||||||
|
@ -143,7 +172,6 @@ func TestPut(t *testing.T) {
|
||||||
require.Equal(t, f, fNew)
|
require.Equal(t, f, fNew)
|
||||||
|
|
||||||
assert.Equal(t, 1, Entries())
|
assert.Equal(t, 1, Entries())
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPin(t *testing.T) {
|
func TestPin(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue