mirror of
https://github.com/rclone/rclone.git
synced 2024-11-22 12:36:38 +08:00
fs/cache: add ClearConfig method to clear all remotes based on Config #4811
This commit is contained in:
parent
f4750928ee
commit
a10fbf16ea
7
fs/cache/cache.go
vendored
7
fs/cache/cache.go
vendored
|
@ -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()
|
||||
|
|
16
fs/cache/cache_test.go
vendored
16
fs/cache/cache_test.go
vendored
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue
Block a user