fs/cache: add ClearConfig method to clear all remotes based on Config #4811

This commit is contained in:
Nick Craig-Wood 2020-11-30 11:52:25 +00:00
parent f4750928ee
commit a10fbf16ea
2 changed files with 23 additions and 0 deletions

7
fs/cache/cache.go vendored
View File

@ -124,6 +124,13 @@ func Put(fsString string, f fs.Fs) {
addMapping(fsString, canonicalName)
}
// ClearConfig deletes all entries which were based on the config name passed in
//
// Returns number of entries deleted
func ClearConfig(name string) (deleted int) {
return c.DeletePrefix(name + ":")
}
// Clear removes everything from the cache
func Clear() {
c.Clear()

View File

@ -166,6 +166,22 @@ func TestPin(t *testing.T) {
Unpin(f2)
}
func TestClearConfig(t *testing.T) {
cleanup, create := mockNewFs(t)
defer cleanup()
assert.Equal(t, 0, c.Entries())
_, err := GetFn(context.Background(), "mock:/file.txt", create)
require.Equal(t, fs.ErrorIsFile, err)
assert.Equal(t, 2, Entries()) // file + parent
assert.Equal(t, 2, ClearConfig("mock"))
assert.Equal(t, 0, Entries())
}
func TestClear(t *testing.T) {
cleanup, create := mockNewFs(t)
defer cleanup()