diff --git a/unixfs/archive/tar/writer.go b/unixfs/archive/tar/writer.go index 4503f5593..7e6f13894 100644 --- a/unixfs/archive/tar/writer.go +++ b/unixfs/archive/tar/writer.go @@ -39,23 +39,25 @@ func NewWriter(ctx context.Context, dag ipld.DAGService, archive bool, compressi } func (w *Writer) writeDir(nd *mdag.ProtoNode, fpath string) error { + dir, err := uio.NewDirectoryFromNode(w.Dag, nd) + if err != nil { + return err + } if err := writeDirHeader(w.TarW, fpath); err != nil { return err } - for i, ng := range ipld.GetDAG(w.ctx, w.Dag, nd) { - child, err := ng.Get(w.ctx) + return dir.ForEachLink(w.ctx, func(l *ipld.Link) error { + child, err := w.Dag.Get(w.ctx, l.Cid) if err != nil { return err } - - npath := path.Join(fpath, nd.Links()[i].Name) + npath := path.Join(fpath, l.Name) if err := w.WriteNode(child, npath); err != nil { return err } - } - - return nil + return nil + }) } func (w *Writer) writeFile(nd *mdag.ProtoNode, pb *upb.Data, fpath string) error { @@ -83,7 +85,7 @@ func (w *Writer) WriteNode(nd ipld.Node, fpath string) error { switch pb.GetType() { case upb.Data_Metadata: fallthrough - case upb.Data_Directory: + case upb.Data_Directory, upb.Data_HAMTShard: return w.writeDir(nd, fpath) case upb.Data_Raw: fallthrough