From e87de7c7e3ed042616e28a350a5e31fcf7bc09bc Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Tue, 10 Aug 2021 18:19:20 +0100 Subject: [PATCH] vfs: fix crash when truncating a just uploaded object - Fixes #5522 --- vfs/file.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/vfs/file.go b/vfs/file.go index 3a829adf6..e30d85692 100644 --- a/vfs/file.go +++ b/vfs/file.go @@ -744,7 +744,6 @@ func (f *File) Truncate(size int64) (err error) { f.mu.Lock() writers := make([]Handle, len(f.writers)) copy(writers, f.writers) - o := f.o f.mu.Unlock() // FIXME: handle closing writer @@ -761,6 +760,12 @@ func (f *File) Truncate(size int64) (err error) { return err } + // if o is nil it isn't valid yet + o, err := f.waitForValidObject() + if err != nil { + return err + } + // If no writers, and size is already correct then all done if o.Size() == size { return nil