From 90ea494338b49a3c2b424009148f3d2087634be0 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Sun, 8 May 2016 16:26:10 -0700 Subject: [PATCH] erasure: waitCloser should implement CloseWithError. (#1543) This is needed so that the other end of the pipe receives and error, cleanups temporary files. --- object-utils.go | 4 ++-- xl-erasure-v1-waitcloser.go | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/object-utils.go b/object-utils.go index 9370c3161..3d0d5d890 100644 --- a/object-utils.go +++ b/object-utils.go @@ -144,9 +144,9 @@ func safeCloseAndRemove(writer io.WriteCloser) error { if ok { return safeWriter.CloseAndRemove() } - pipeWriter, ok := writer.(*io.PipeWriter) + wCloser, ok := writer.(*waitCloser) if ok { - return pipeWriter.CloseWithError(errors.New("Close and error out.")) + return wCloser.CloseWithError(errors.New("Close and error out.")) } return nil } diff --git a/xl-erasure-v1-waitcloser.go b/xl-erasure-v1-waitcloser.go index 4af554378..f8b1d8bba 100644 --- a/xl-erasure-v1-waitcloser.go +++ b/xl-erasure-v1-waitcloser.go @@ -43,6 +43,16 @@ func (b *waitCloser) Close() error { return err } +// CloseWithError closes the writer; subsequent read to the read +// half of the pipe will return the error err. +func (b *waitCloser) CloseWithError(err error) error { + w, ok := b.writer.(*io.PipeWriter) + if ok { + return w.CloseWithError(err) + } + return err +} + // release the Close, causing it to unblock. Only call this // once. Calling it multiple times results in a panic. func (b *waitCloser) release() {