make the tar writer handle sharded ipfs directories
makes ipfs get work on sharded directories fixes #4871 License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>
Steven Allen committed
Mar 23, 2018 at 15:56 UTC
234ad1811d9451bb154b4d7889018f802c779c1a
1 file changed
+10
-8
unixfs/archive/tar/writer.go
+10
-8
@@ -39,23 +39,25 @@ func NewWriter(ctx context.Context, dag ipld.DAGService, archive bool, compressi
39
}
40
41
func (w *Writer) writeDir(nd *mdag.ProtoNode, fpath string) error {
42
+ dir, err := uio.NewDirectoryFromNode(w.Dag, nd)
43
+ if err != nil {
44
+ return err
45
+ }
46
if err := writeDirHeader(w.TarW, fpath); err != nil {
47
return err
48
}
49
46
- for i, ng := range ipld.GetDAG(w.ctx, w.Dag, nd) {
47
- child, err := ng.Get(w.ctx)
50
+ return dir.ForEachLink(w.ctx, func(l *ipld.Link) error {
51
+ child, err := w.Dag.Get(w.ctx, l.Cid)
52
if err != nil {
53
return err
54
}
51
-
52
- npath := path.Join(fpath, nd.Links()[i].Name)
55
+ npath := path.Join(fpath, l.Name)
56
if err := w.WriteNode(child, npath); err != nil {
57
return err
58
}
56
- }
57
-
58
- return nil
59
+ return nil
60
+ })
61
}
62
63
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 {
85
switch pb.GetType() {
86
case upb.Data_Metadata:
87
fallthrough
86
- case upb.Data_Directory:
88
+ case upb.Data_Directory, upb.Data_HAMTShard:
89
return w.writeDir(nd, fpath)
90
case upb.Data_Raw:
91
fallthrough