1
0
Fork 0
forked from mirrors/tar-split

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

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