From 919e28b8bf1b1da893aae606f11d57f9692d3a26 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Tue, 8 Nov 2022 11:44:03 +0000 Subject: [PATCH] lib/cache: fix alias backend shutting down too soon Before this patch, when an alias backend was created it would be renamed to be canonical and in the process Shutdown would be called on it. This was particularly noticeable with the dropbox backend which gave this error when uploading files after the backend was Shutdown. Failed to copy: upload failed: batcher is shutting down This patch fixes the cache Rename code not to finalize objects if the object that is being overwritten is the same as the existing object. See: https://forum.rclone.org/t/upload-failed-batcher-is-shutting-down/33900 --- lib/cache/cache.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/cache/cache.go b/lib/cache/cache.go index 8e03819bc..cbcf78796 100644 --- a/lib/cache/cache.go +++ b/lib/cache/cache.go @@ -190,9 +190,11 @@ func (c *Cache) Rename(oldKey, newKey string) (value interface{}, found bool) { c.mu.Lock() if newEntry, newFound := c.cache[newKey]; newFound { // If new entry is found use that - if _, oldFound := c.cache[oldKey]; oldFound { - // If there's an old entry, we drop it and also try shutdown. - c.finalize(c.cache[oldKey].value) + if oldEntry, oldFound := c.cache[oldKey]; oldFound { + // If there's an old entry that is different we must finalize it + if newEntry.value != oldEntry.value { + c.finalize(c.cache[oldKey].value) + } } delete(c.cache, oldKey) value, found = newEntry.value, newFound