mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-26 15:42:21 +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:
@ -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 {
|
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 {
|
if err := writeDirHeader(w.TarW, fpath); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, ng := range ipld.GetDAG(w.ctx, w.Dag, nd) {
|
return dir.ForEachLink(w.ctx, func(l *ipld.Link) error {
|
||||||
child, err := ng.Get(w.ctx)
|
child, err := w.Dag.Get(w.ctx, l.Cid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
npath := path.Join(fpath, l.Name)
|
||||||
npath := path.Join(fpath, nd.Links()[i].Name)
|
|
||||||
if err := w.WriteNode(child, npath); err != nil {
|
if err := w.WriteNode(child, npath); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
return nil
|
||||||
|
})
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Writer) writeFile(nd *mdag.ProtoNode, pb *upb.Data, fpath string) error {
|
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() {
|
switch pb.GetType() {
|
||||||
case upb.Data_Metadata:
|
case upb.Data_Metadata:
|
||||||
fallthrough
|
fallthrough
|
||||||
case upb.Data_Directory:
|
case upb.Data_Directory, upb.Data_HAMTShard:
|
||||||
return w.writeDir(nd, fpath)
|
return w.writeDir(nd, fpath)
|
||||||
case upb.Data_Raw:
|
case upb.Data_Raw:
|
||||||
fallthrough
|
fallthrough
|
||||||
|
Reference in New Issue
Block a user