-
Notifications
You must be signed in to change notification settings - Fork 1
/
resolve.go
41 lines (33 loc) · 1.08 KB
/
resolve.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package io
import (
"context"
dag "github.com/ipsn/go-ipfs/gxlibs/github.com/ipfs/go-merkledag"
ft "github.com/ipsn/go-ipfs/gxlibs/github.com/ipfs/go-unixfs"
hamt "github.com/ipsn/go-ipfs/gxlibs/github.com/ipfs/go-unixfs/hamt"
ipld "github.com/ipsn/go-ipfs/gxlibs/github.com/ipfs/go-ipld-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 ipld.NodeGetter, nd ipld.Node, names []string) (*ipld.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)
}