vfs: fix failed to _ensure cache internal error: downloaders is nil error

This error was caused by renaming an open file.

When the file was renamed in the cache, the downloaders were cleared,
however the downloaders were not re-opened when needed again, instead
this error was generated.

This fix re-opens the downloaders if they have been closed by renaming
the file.

Fixes #5984
This commit is contained in:
Nick Craig-Wood 2022-02-18 16:23:26 +00:00
parent 2339172df2
commit ec72432cec
1 changed files with 4 additions and 1 deletions

View File

@ -1128,7 +1128,10 @@ func (item *Item) _ensure(offset, size int64) (err error) {
return item.downloaders.EnsureDownloader(r)
}
if item.downloaders == nil {
return errors.New("internal error: downloaders is nil")
// Downloaders can be nil here if the file has been
// renamed, so need to make some more downloaders
// OK to call downloaders constructor with item.mu held
item.downloaders = downloaders.New(item, item.c.opt, item.name, item.o)
}
return item.downloaders.Download(r)
}