From 6e38573de2ab9ae03937762754dcde175ee2d9b6 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Fri, 24 Apr 2015 15:37:53 +0200 Subject: [PATCH] archive/tar: fix error message Write should return ErrWriteAfterClose instead of ErrWriteTooLong when called after Close. Change-Id: If5ec4ef924e4c56489e0d426976f7e5fad79be9b Reviewed-on: https://go-review.googlesource.com/9259 Reviewed-by: Brad Fitzpatrick Signed-off-by: Vincent Batts --- archive/tar/writer.go | 2 +- archive/tar/writer_test.go | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/archive/tar/writer.go b/archive/tar/writer.go index dafb2ca..9dbc01a 100644 --- a/archive/tar/writer.go +++ b/archive/tar/writer.go @@ -355,7 +355,7 @@ func paxHeader(msg string) string { // hdr.Size bytes are written after WriteHeader. func (tw *Writer) Write(b []byte) (n int, err error) { if tw.closed { - err = ErrWriteTooLong + err = ErrWriteAfterClose return } overwrite := false diff --git a/archive/tar/writer_test.go b/archive/tar/writer_test.go index 5e42e32..650899a 100644 --- a/archive/tar/writer_test.go +++ b/archive/tar/writer_test.go @@ -489,3 +489,20 @@ func TestValidTypeflagWithPAXHeader(t *testing.T) { } } } + +func TestWriteAfterClose(t *testing.T) { + var buffer bytes.Buffer + tw := NewWriter(&buffer) + + hdr := &Header{ + Name: "small.txt", + Size: 5, + } + if err := tw.WriteHeader(hdr); err != nil { + t.Fatalf("Failed to write header: %s", err) + } + tw.Close() + if _, err := tw.Write([]byte("Kilts")); err != ErrWriteAfterClose { + t.Fatalf("Write: got %v; want ErrWriteAfterClose", err) + } +}