@cryptotaxi247 / kubo / commits / 23dd82f54

Fix t0090 tar&gz unexpected EOF error

License: MIT Signed-off-by: rht <rhtbot@gmail.com>

rht committed Sep 13, 2015 at 15:41 UTC 23dd82f5490edaf4a1685e1a2227f764d29e700c
3 files changed +31 -12
test/sharness/t0090-get.sh
+3 -6
@@ -51,8 +51,7 @@ test_get_cmd() {
51 test_cmp expected actual
52 '
53
54 - # TODO: determine why this fails
55 - test_expect_failure "ipfs get -a archive output is valid" '
54 + test_expect_success "ipfs get -a archive output is valid" '
55 tar -xf "$HASH".tar &&
56 test_cmp "$HASH" data &&
57 rm "$HASH".tar &&
@@ -68,8 +67,7 @@ test_get_cmd() {
67 test_cmp expected actual
68 '
69
71 - # TODO(mappum)
72 - test_expect_failure "gzipped tar archive output is valid" '
70 + test_expect_success "gzipped tar archive output is valid" '
71 tar -zxf "$HASH".tar.gz &&
72 test_cmp "$HASH" data &&
73 rm "$HASH".tar.gz &&
@@ -105,8 +103,7 @@ test_get_cmd() {
103 test_cmp expected actual
104 '
105
108 - # TODO(mappum)
109 - test_expect_failure "gzipped tar archive output is valid (directory)" '
106 + test_expect_success "gzipped tar archive output is valid (directory)" '
107 tar -zxf "$HASH2".tar.gz &&
108 test_cmp dir/a "$HASH2"/a &&
109 test_cmp dir/b/c "$HASH2"/b/c &&
unixfs/archive/archive.go
+23 -4
@@ -17,6 +17,18 @@ import (
17 // TODO: does this need to be configurable?
18 var DefaultBufSize = 1048576
19
20 +type identityWriteCloser struct {
21 + w io.Writer
22 +}
23 +
24 +func (i *identityWriteCloser) Write(p []byte) (int, error) {
25 + return i.w.Write(p)
26 +}
27 +
28 +func (i *identityWriteCloser) Close() error {
29 + return nil
30 +}
31 +
32 // DagArchive is equivalent to `ipfs getdag $hash | maybe_tar | maybe_gzip`
33 func DagArchive(ctx cxt.Context, nd *mdag.Node, name string, dag mdag.DAGService, archive bool, compression int) (io.Reader, error) {
34
@@ -29,15 +41,16 @@ func DagArchive(ctx cxt.Context, nd *mdag.Node, name string, dag mdag.DAGService
41 bufw := bufio.NewWriterSize(pipew, DefaultBufSize)
42
43 // compression determines whether to use gzip compression.
32 - var maybeGzw io.Writer
44 + var maybeGzw io.WriteCloser
45 + var err error
46 if compression != gzip.NoCompression {
34 - var err error
47 maybeGzw, err = gzip.NewWriterLevel(bufw, compression)
48 if err != nil {
49 + pipew.CloseWithError(err)
50 return nil, err
51 }
52 } else {
40 - maybeGzw = bufw
53 + maybeGzw = &identityWriteCloser{bufw}
54 }
55
56 if !archive && compression != gzip.NoCompression {
@@ -53,6 +66,11 @@ func DagArchive(ctx cxt.Context, nd *mdag.Node, name string, dag mdag.DAGService
66 pipew.CloseWithError(err)
67 return
68 }
69 + maybeGzw.Close()
70 + if err := bufw.Flush(); err != nil {
71 + pipew.CloseWithError(err)
72 + return
73 + }
74 pipew.Close() // everything seems to be ok.
75 }()
76 } else {
@@ -70,11 +88,12 @@ func DagArchive(ctx cxt.Context, nd *mdag.Node, name string, dag mdag.DAGService
88 pipew.CloseWithError(err)
89 return
90 }
91 + w.Close()
92 + maybeGzw.Close()
93 if err := bufw.Flush(); err != nil {
94 pipew.CloseWithError(err)
95 return
96 }
77 - w.Close()
97 pipew.Close() // everything seems to be ok.
98 }()
99 }
unixfs/archive/tar/writer.go
+5 -2
@@ -60,8 +60,11 @@ func (w *Writer) writeFile(nd *mdag.Node, pb *upb.Data, fpath string) error {
60 }
61
62 dagr := uio.NewDataFileReader(w.ctx, nd, pb, w.Dag)
63 - _, err := dagr.WriteTo(w.TarW)
64 - return err
63 + if _, err := dagr.WriteTo(w.TarW); err != nil {
64 + return err
65 + }
66 + w.TarW.Flush()
67 + return nil
68 }
69
70 func (w *Writer) WriteNode(nd *mdag.Node, fpath string) error {