From e0e9886972e2ab8ae9190428d1d3030c5c80c483 Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Wed, 22 Jul 2015 11:32:18 -0400 Subject: [PATCH] tar/asm: return instead of break https://github.com/vbatts/docker/commit/5ddec2ae4a74552cb358bae90e272398a957cfc4#commitcomment-12290378 Reported-by: Tibor Vass --- tar/asm/assemble.go | 10 +++++----- tar/asm/assemble_test.go | 9 +-------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/tar/asm/assemble.go b/tar/asm/assemble.go index d18bfc5..1bef97b 100644 --- a/tar/asm/assemble.go +++ b/tar/asm/assemble.go @@ -27,13 +27,13 @@ func NewOutputTarStream(fg storage.FileGetter, up storage.Unpacker) io.ReadClose entry, err := up.Next() if err != nil { pw.CloseWithError(err) - break + return } switch entry.Type { case storage.SegmentType: if _, err := pw.Write(entry.Payload); err != nil { pw.CloseWithError(err) - break + return } case storage.FileType: if entry.Size == 0 { @@ -42,14 +42,14 @@ func NewOutputTarStream(fg storage.FileGetter, up storage.Unpacker) io.ReadClose fh, err := fg.Get(entry.Name) if err != nil { pw.CloseWithError(err) - break + return } c := crc64.New(storage.CRCTable) tRdr := io.TeeReader(fh, c) if _, err := io.Copy(pw, tRdr); err != nil { fh.Close() pw.CloseWithError(err) - break + return } if !bytes.Equal(c.Sum(nil), entry.Payload) { // I would rather this be a comparable ErrInvalidChecksum or such, @@ -57,7 +57,7 @@ func NewOutputTarStream(fg storage.FileGetter, up storage.Unpacker) io.ReadClose // _which_ file would be lost... fh.Close() pw.CloseWithError(fmt.Errorf("file integrity checksum failed for %q", entry.Name)) - break + return } fh.Close() } diff --git a/tar/asm/assemble_test.go b/tar/asm/assemble_test.go index c3bda7a..7cf44dc 100644 --- a/tar/asm/assemble_test.go +++ b/tar/asm/assemble_test.go @@ -110,10 +110,6 @@ func TestTarStreamMangledGetterPutter(t *testing.T) { } } } - - // TODO test a mangled relative path assembly - // next we'll use these to produce a tar stream. - //_ = NewOutputTarStream(fgp, nil) } func TestTarStream(t *testing.T) { @@ -171,10 +167,7 @@ func TestTarStream(t *testing.T) { rc := NewOutputTarStream(fgp, sup) h1 := sha1.New() - tRdr1 := io.TeeReader(rc, h1) - - // read it all to the bit bucket - i, err = io.Copy(ioutil.Discard, tRdr1) + i, err = io.Copy(h1, rc) if err != nil { t.Fatal(err) }