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
This commit is contained in:
Nick Craig-Wood 2022-11-08 11:44:03 +00:00
parent 3a3bc5a1ae
commit 919e28b8bf

8
lib/cache/cache.go vendored
View File

@ -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