diff --git a/backend/cache/cache.go b/backend/cache/cache.go index 8bf2a2187..81bd1d8bb 100644 --- a/backend/cache/cache.go +++ b/backend/cache/cache.go @@ -473,18 +473,20 @@ 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) + if cleanPath(remote) != "" { + // 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 } - // 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) + if !f.cache.HasEntry(path.Join(f.Root(), remote)) { + return out, errors.Errorf("%s doesn't exist in cache", remote) + } } co := NewObject(f, remote) diff --git a/backend/cache/cache_internal_test.go b/backend/cache/cache_internal_test.go index 9158f35df..59c969743 100644 --- a/backend/cache/cache_internal_test.go +++ b/backend/cache/cache_internal_test.go @@ -618,6 +618,9 @@ func TestInternalChangeSeenAfterRc(t *testing.T) { if !runInstance.useMount { t.Skipf("needs mount") } + if !runInstance.wrappedIsExternal { + t.Skipf("needs drive") + } cfs, err := runInstance.getCacheFs(rootFs) require.NoError(t, err) @@ -655,6 +658,31 @@ func TestInternalChangeSeenAfterRc(t *testing.T) { co, err = rootFs.NewObject("data.bin") require.NoError(t, err) require.Equal(t, wrappedTime.Unix(), co.ModTime().Unix()) + li1, err := runInstance.list(t, rootFs, "") + + // create some rand test data + testData2 := randStringBytes(int(chunkSize)) + runInstance.writeObjectBytes(t, cfs.UnWrap(), runInstance.encryptRemoteIfNeeded(t, "test2"), testData2) + + // list should have 1 item only + li1, err = runInstance.list(t, rootFs, "") + require.Len(t, li1, 1) + + m = make(map[string]string) + res2, err := http.Post("http://localhost:5572/cache/expire?remote=/", "application/json; charset=utf-8", strings.NewReader("")) + require.NoError(t, err) + defer func() { + _ = res2.Body.Close() + }() + _ = json.NewDecoder(res2.Body).Decode(&m) + require.Contains(t, m, "status") + require.Contains(t, m, "message") + require.Equal(t, "ok", m["status"]) + require.Contains(t, m["message"], "cached directory cleared") + + // list should have 2 items now + li2, err := runInstance.list(t, rootFs, "") + require.Len(t, li2, 2) } func TestInternalCacheWrites(t *testing.T) {