package io import ( "context" dag "gitlab.dms3.io/dms3/go-merkledag" ft "gitlab.dms3.io/dms3/go-unixfs" hamt "gitlab.dms3.io/dms3/go-unixfs/hamt" ld "gitlab.dms3.io/dms3/go-ld-format" ) // ResolveUnixfsOnce resolves a single hop of a path through a graph in a // unixfs context. This includes handling traversing sharded directories. func ResolveUnixfsOnce(ctx context.Context, ds ld.NodeGetter, nd ld.Node, names []string) (*ld.Link, []string, error) { pn, ok := nd.(*dag.ProtoNode) if ok { fsn, err := ft.FSNodeFromBytes(pn.Data()) if err != nil { // Not a unixfs node, use standard object traversal code return nd.ResolveLink(names) } if fsn.Type() == ft.THAMTShard { rods := dag.NewReadOnlyDagService(ds) s, err := hamt.NewHamtFromDag(rods, nd) if err != nil { return nil, nil, err } out, err := s.Find(ctx, names[0]) if err != nil { return nil, nil, err } return out, names[1:], nil } } return nd.ResolveLink(names) }