From 234ad1811d9451bb154b4d7889018f802c779c1a Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 23 Mar 2018 15:56:57 -0700 Subject: [PATCH] make the tar writer handle sharded ipfs directories makes ipfs get work on sharded directories fixes #4871 License: MIT Signed-off-by: Steven Allen --- unixfs/archive/tar/writer.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) 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