diff --git a/test/sharness/t0090-get.sh b/test/sharness/t0090-get.sh index f00bf7e89..57fe304f9 100755 --- a/test/sharness/t0090-get.sh +++ b/test/sharness/t0090-get.sh @@ -51,8 +51,7 @@ test_get_cmd() { test_cmp expected actual ' - # TODO: determine why this fails - test_expect_failure "ipfs get -a archive output is valid" ' + test_expect_success "ipfs get -a archive output is valid" ' tar -xf "$HASH".tar && test_cmp "$HASH" data && rm "$HASH".tar && @@ -68,8 +67,7 @@ test_get_cmd() { test_cmp expected actual ' - # TODO(mappum) - test_expect_failure "gzipped tar archive output is valid" ' + test_expect_success "gzipped tar archive output is valid" ' tar -zxf "$HASH".tar.gz && test_cmp "$HASH" data && rm "$HASH".tar.gz && @@ -105,8 +103,7 @@ test_get_cmd() { test_cmp expected actual ' - # TODO(mappum) - test_expect_failure "gzipped tar archive output is valid (directory)" ' + test_expect_success "gzipped tar archive output is valid (directory)" ' tar -zxf "$HASH2".tar.gz && test_cmp dir/a "$HASH2"/a && test_cmp dir/b/c "$HASH2"/b/c && diff --git a/unixfs/archive/archive.go b/unixfs/archive/archive.go index d530461e7..e1faf5a33 100644 --- a/unixfs/archive/archive.go +++ b/unixfs/archive/archive.go @@ -17,6 +17,18 @@ import ( // TODO: does this need to be configurable? var DefaultBufSize = 1048576 +type identityWriteCloser struct { + w io.Writer +} + +func (i *identityWriteCloser) Write(p []byte) (int, error) { + return i.w.Write(p) +} + +func (i *identityWriteCloser) Close() error { + return nil +} + // DagArchive is equivalent to `ipfs getdag $hash | maybe_tar | maybe_gzip` func DagArchive(ctx cxt.Context, nd *mdag.Node, name string, dag mdag.DAGService, archive bool, compression int) (io.Reader, error) { @@ -29,15 +41,16 @@ func DagArchive(ctx cxt.Context, nd *mdag.Node, name string, dag mdag.DAGService bufw := bufio.NewWriterSize(pipew, DefaultBufSize) // compression determines whether to use gzip compression. - var maybeGzw io.Writer + var maybeGzw io.WriteCloser + var err error if compression != gzip.NoCompression { - var err error maybeGzw, err = gzip.NewWriterLevel(bufw, compression) if err != nil { + pipew.CloseWithError(err) return nil, err } } else { - maybeGzw = bufw + maybeGzw = &identityWriteCloser{bufw} } if !archive && compression != gzip.NoCompression { @@ -53,6 +66,11 @@ func DagArchive(ctx cxt.Context, nd *mdag.Node, name string, dag mdag.DAGService pipew.CloseWithError(err) return } + maybeGzw.Close() + if err := bufw.Flush(); err != nil { + pipew.CloseWithError(err) + return + } pipew.Close() // everything seems to be ok. }() } else { @@ -70,11 +88,12 @@ func DagArchive(ctx cxt.Context, nd *mdag.Node, name string, dag mdag.DAGService pipew.CloseWithError(err) return } + w.Close() + maybeGzw.Close() if err := bufw.Flush(); err != nil { pipew.CloseWithError(err) return } - w.Close() pipew.Close() // everything seems to be ok. }() } diff --git a/unixfs/archive/tar/writer.go b/unixfs/archive/tar/writer.go index 4953be90e..6536e443e 100644 --- a/unixfs/archive/tar/writer.go +++ b/unixfs/archive/tar/writer.go @@ -60,8 +60,11 @@ func (w *Writer) writeFile(nd *mdag.Node, pb *upb.Data, fpath string) error { } dagr := uio.NewDataFileReader(w.ctx, nd, pb, w.Dag) - _, err := dagr.WriteTo(w.TarW) - return err + if _, err := dagr.WriteTo(w.TarW); err != nil { + return err + } + w.TarW.Flush() + return nil } func (w *Writer) WriteNode(nd *mdag.Node, fpath string) error {