Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix resolving links in sharded directories on gateway #5271

Merged
merged 5 commits into from
Jul 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 33 additions & 12 deletions path/resolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,46 @@ func (r *Resolver) ResolveToLastNode(ctx context.Context, fpath path.Path) (ipld
}

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 {
return nil, nil, err
}

switch val := val.(type) {
case *ipld.Link:
next, err := val.GetNode(ctx, r.DAG)
if err != nil {
return nil, nil, err
}
nd = next
p = rest
default:
return nd, p, nil
next, err := lnk.GetNode(ctx, r.DAG)
if err != nil {
return nil, nil, err
}
nd = next
p = rest
}

if len(p) == 0 {
return nd, nil, nil
}

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:
return nd, p, nil
}
}

// ResolvePath fetches the node for given path. It returns the last item
Expand Down
9 changes: 9 additions & 0 deletions test/sharness/t0260-sharding.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ test_expect_success "'ipfs ls --resolve-type=false' admits missing block" '
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() {
exphash="$1"
Expand Down