1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-26 07:28:20 +08:00

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>
This commit is contained in:
Steven Allen
2018-03-23 15:56:57 -07:00
parent 3cbf97bea1
commit 234ad1811d

View File

@ -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