Skip to content

Commit

Permalink
fix coreapi unixfs resolving
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Jeromy <jeromyj@gmail.com>
  • Loading branch information
whyrusleeping committed Apr 30, 2017
1 parent 0597a04 commit 8a7c6af
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 7 additions & 1 deletion core/coreapi/coreapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
core "github.com/ipfs/go-ipfs/core"
coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
ipfspath "github.com/ipfs/go-ipfs/path"
uio "github.com/ipfs/go-ipfs/unixfs/io"

cid "gx/ipfs/QmYhQaCYEcaPPjxJX7YcPcVKkQfRy6sJ7B3XmGFk82XYdQ/go-cid"
)
Expand Down Expand Up @@ -42,8 +43,13 @@ func (api *CoreAPI) ResolvePath(ctx context.Context, p coreiface.Path) (coreifac
return p, nil
}

r := &ipfspath.Resolver{
DAG: api.node.DAG,
ResolveOnce: uio.ResolveUnixfsOnce,
}

p2 := ipfspath.FromString(p.String())
node, err := core.Resolve(ctx, api.node.Namesys, api.node.Resolver, p2)
node, err := core.Resolve(ctx, api.node.Namesys, r, p2)
if err == core.ErrNoNamesys {
return nil, coreiface.ErrOffline
} else if err != nil {
Expand Down
11 changes: 10 additions & 1 deletion core/coreapi/unixfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,16 @@ func (api *UnixfsAPI) Ls(ctx context.Context, p coreiface.Path) ([]*coreiface.Li
return nil, err
}

l := dagnode.Links()
dir, err := uio.NewDirectoryFromNode(api.node.DAG, dagnode)
if err != nil {
return nil, err
}

l, err := dir.Links(ctx)
if err != nil {
return nil, err
}

links := make([]*coreiface.Link, len(l))
for i, l := range l {
links[i] = &coreiface.Link{l.Name, l.Size, l.Cid}
Expand Down

0 comments on commit 8a7c6af

Please sign in to comment.