1
0
Fork 1
mirror of https://github.com/vbatts/tar-split.git synced 2024-11-15 04:58:36 +00:00

tar/asm: return instead of break

5ddec2ae4a (commitcomment-12290378)

Reported-by: Tibor Vass <tibor@docker.com>
This commit is contained in:
Vincent Batts 2015-07-22 11:32:18 -04:00
parent c2c2dde4cb
commit e0e9886972
2 changed files with 6 additions and 13 deletions

View file

@ -27,13 +27,13 @@ func NewOutputTarStream(fg storage.FileGetter, up storage.Unpacker) io.ReadClose
entry, err := up.Next() entry, err := up.Next()
if err != nil { if err != nil {
pw.CloseWithError(err) pw.CloseWithError(err)
break return
} }
switch entry.Type { switch entry.Type {
case storage.SegmentType: case storage.SegmentType:
if _, err := pw.Write(entry.Payload); err != nil { if _, err := pw.Write(entry.Payload); err != nil {
pw.CloseWithError(err) pw.CloseWithError(err)
break return
} }
case storage.FileType: case storage.FileType:
if entry.Size == 0 { if entry.Size == 0 {
@ -42,14 +42,14 @@ func NewOutputTarStream(fg storage.FileGetter, up storage.Unpacker) io.ReadClose
fh, err := fg.Get(entry.Name) fh, err := fg.Get(entry.Name)
if err != nil { if err != nil {
pw.CloseWithError(err) pw.CloseWithError(err)
break return
} }
c := crc64.New(storage.CRCTable) c := crc64.New(storage.CRCTable)
tRdr := io.TeeReader(fh, c) tRdr := io.TeeReader(fh, c)
if _, err := io.Copy(pw, tRdr); err != nil { if _, err := io.Copy(pw, tRdr); err != nil {
fh.Close() fh.Close()
pw.CloseWithError(err) pw.CloseWithError(err)
break return
} }
if !bytes.Equal(c.Sum(nil), entry.Payload) { if !bytes.Equal(c.Sum(nil), entry.Payload) {
// I would rather this be a comparable ErrInvalidChecksum or such, // 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... // _which_ file would be lost...
fh.Close() fh.Close()
pw.CloseWithError(fmt.Errorf("file integrity checksum failed for %q", entry.Name)) pw.CloseWithError(fmt.Errorf("file integrity checksum failed for %q", entry.Name))
break return
} }
fh.Close() fh.Close()
} }

View file

@ -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) { func TestTarStream(t *testing.T) {
@ -171,10 +167,7 @@ func TestTarStream(t *testing.T) {
rc := NewOutputTarStream(fgp, sup) rc := NewOutputTarStream(fgp, sup)
h1 := sha1.New() h1 := sha1.New()
tRdr1 := io.TeeReader(rc, h1) i, err = io.Copy(h1, rc)
// read it all to the bit bucket
i, err = io.Copy(ioutil.Discard, tRdr1)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }