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) }