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

Merge pull request #5271 from ipfs/fix/5270

Fix resolving links in sharded directories on gateway
This commit is contained in:
Whyrusleeping
2018-07-23 12:53:42 -07:00
committed by GitHub
2 changed files with 42 additions and 12 deletions

View File

@ -69,27 +69,48 @@ func (r *Resolver) ResolveToLastNode(ctx context.Context, fpath path.Path) (ipld
} }
for len(p) > 0 { for len(p) > 0 {
val, rest, err := nd.Resolve(p) lnk, rest, err := r.ResolveOnce(ctx, r.DAG, nd, p)
// Note: have to drop the error here as `ResolveOnce` doesn't handle 'leaf'
// paths (so e.g. for `echo '{"foo":123}' | ipfs dag put` we wouldn't be
// able to resolve `zdpu[...]/foo`)
if lnk == nil {
break
}
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
switch val := val.(type) { next, err := lnk.GetNode(ctx, r.DAG)
case *ipld.Link:
next, err := val.GetNode(ctx, r.DAG)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
nd = next nd = next
p = rest p = rest
}
if len(p) == 0 {
return nd, nil, nil
}
// Confirm the path exists within the object
val, rest, err := nd.Resolve(p)
if err != nil {
return nil, nil, err
}
if len(rest) > 0 {
return nil, nil, errors.New("path failed to resolve fully")
}
switch val.(type) {
case *ipld.Link:
return nil, nil, errors.New("inconsistent ResolveOnce / nd.Resolve")
default: default:
return nd, p, nil return nd, p, nil
} }
} }
return nd, nil, nil
}
// ResolvePath fetches the node for given path. It returns the last item // ResolvePath fetches the node for given path. It returns the last item
// returned by ResolvePathComponents. // returned by ResolvePathComponents.
func (r *Resolver) ResolvePath(ctx context.Context, fpath path.Path) (ipld.Node, error) { func (r *Resolver) ResolvePath(ctx context.Context, fpath path.Path) (ipld.Node, error) {

View File

@ -76,6 +76,15 @@ test_expect_success "'ipfs ls --resolve-type=false' admits missing block" '
test_cmp sharded_out missing_out test_cmp sharded_out missing_out
' '
test_launch_ipfs_daemon
test_expect_success "gateway can resolve sharded dirs" '
echo 100 > expected &&
curl -sfo actual "http://127.0.0.1:$GWAY_PORT/ipfs/$SHARDED/file100" &&
test_cmp expected actual
'
test_kill_ipfs_daemon
test_add_large_dir_v1() { test_add_large_dir_v1() {
exphash="$1" exphash="$1"