From 078d705dbec21fc4ad53314de696ab9d66edf722 Mon Sep 17 00:00:00 2001 From: remusb Date: Thu, 15 Mar 2018 11:05:45 +0200 Subject: [PATCH] cache: notify vfs and support crypt in rpc - #2111 --- backend/cache/cache.go | 14 ++++++++++++++ backend/cache/cache_internal_test.go | 2 +- docs/content/cache.md | 2 ++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/backend/cache/cache.go b/backend/cache/cache.go index cf79273f3..f8766d2c2 100644 --- a/backend/cache/cache.go +++ b/backend/cache/cache.go @@ -447,6 +447,16 @@ func (f *Fs) httpExpireRemote(in rc.Params) (out rc.Params, err error) { withData = true } + // if it's wrapped by crypt we need to check what format we got + if cryptFs, yes := f.isWrappedByCrypt(); yes { + _, err := cryptFs.DecryptFileName(remote) + // if it failed to decrypt then it is a decrypted format and we need to encrypt it + if err != nil { + remote = cryptFs.EncryptFileName(remote) + } + // else it's an encrypted format and we can use it as it is + } + if !f.cache.HasEntry(path.Join(f.Root(), remote)) { return out, errors.Errorf("%s doesn't exist in cache", remote) } @@ -459,6 +469,8 @@ func (f *Fs) httpExpireRemote(in rc.Params) (out rc.Params, err error) { if err != nil { return out, errors.WithMessage(err, "error expiring directory") } + // notify vfs too + f.notifyChangeUpstream(cd.Remote(), fs.EntryDirectory) out["status"] = "ok" out["message"] = fmt.Sprintf("cached directory cleared: %v", remote) return out, nil @@ -469,6 +481,8 @@ func (f *Fs) httpExpireRemote(in rc.Params) (out rc.Params, err error) { if err != nil { return out, errors.WithMessage(err, "error expiring file") } + // notify vfs too + f.notifyChangeUpstream(co.Remote(), fs.EntryObject) if withData { // safe to ignore as the file might not have been open _ = os.RemoveAll(path.Join(f.cache.dataPath, co.abs())) diff --git a/backend/cache/cache_internal_test.go b/backend/cache/cache_internal_test.go index 9af01e242..abf8d55ec 100644 --- a/backend/cache/cache_internal_test.go +++ b/backend/cache/cache_internal_test.go @@ -645,7 +645,7 @@ func TestInternalChangeSeenAfterRc(t *testing.T) { require.NotEqual(t, o.ModTime().String(), co.ModTime().String()) m := make(map[string]string) - res, err := http.Post(fmt.Sprintf("http://localhost:5572/cache/expire?remote=%s", runInstance.encryptRemoteIfNeeded(t, "data.bin")), "application/json; charset=utf-8", strings.NewReader("")) + res, err := http.Post(fmt.Sprintf("http://localhost:5572/cache/expire?remote=%s", "data.bin"), "application/json; charset=utf-8", strings.NewReader("")) require.NoError(t, err) defer func() { _ = res.Body.Close() diff --git a/docs/content/cache.md b/docs/content/cache.md index c4d112eaa..3dc02a1cd 100644 --- a/docs/content/cache.md +++ b/docs/content/cache.md @@ -248,6 +248,8 @@ By default, the listener is disabled if you do not add the flag. ### rc cache/expire Purge a remote from the cache backend. Supports either a directory or a file. +It supports both encrypted and unencrypted file names if cache is wrapped by crypt. + Params: - **remote** = path to remote **(required)** - **withData** = true/false to delete cached data (chunks) as well _(optional, false by default)_