internal/gcsfs: leave reader as true nil in case of error
Writing typed nil to an the reader field confused Close. Don't write to
it in case of error.
For golang/go#51797.
Change-Id: Idf81d2d75d9b7bc0452e3a07573048f23a635c6a
Reviewed-on: https://go-review.googlesource.com/c/build/+/411057
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Heschi Kreinick <heschi@google.com>
Auto-Submit: Heschi Kreinick <heschi@google.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
diff --git a/internal/gcsfs/gcsfs.go b/internal/gcsfs/gcsfs.go
index d29d806..c105ae2 100644
--- a/internal/gcsfs/gcsfs.go
+++ b/internal/gcsfs/gcsfs.go
@@ -168,11 +168,11 @@
func (f *GCSFile) Read(b []byte) (int, error) {
if f.reader == nil {
- var err error
- f.reader, err = f.fs.object(f.name).NewReader(f.fs.ctx)
+ reader, err := f.fs.object(f.name).NewReader(f.fs.ctx)
if err != nil {
return 0, f.translateError("read", err)
}
+ f.reader = reader
}
n, err := f.reader.Read(b)
return n, f.translateError("read", err)