Skip to content

Commit

Permalink
cmds/refs: fix ipfs refs for sharded directories
Browse files Browse the repository at this point in the history
fixes ipfs#6596
  • Loading branch information
Stebalien authored and Walter Beegle committed Jun 8, 2020
1 parent 7f62b20 commit 3ebcae7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
22 changes: 8 additions & 14 deletions core/commands/refs.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
cidenc "github.com/ipfs/go-cidutil/cidenc"
cmds "github.com/ipfs/go-ipfs-cmds"
ipld "github.com/ipfs/go-ipld-format"
merkledag "github.com/ipfs/go-merkledag"
iface "github.com/ipfs/interface-go-ipfs-core"
path "github.com/ipfs/interface-go-ipfs-core/path"
)
Expand Down Expand Up @@ -103,15 +102,14 @@ NOTE: List all references recursively by using the flag '-r'.
format = "<src> -> <dst>"
}

// TODO: use session for resolving as well.
objs, err := objectsForPaths(ctx, api, req.Arguments)
if err != nil {
return err
}

rw := RefWriter{
res: res,
DAG: merkledag.NewSession(ctx, api.Dag()),
DAG: api.Dag(),
Ctx: ctx,
Unique: unique,
PrintFmt: format,
Expand Down Expand Up @@ -166,16 +164,16 @@ Displays the hashes of all local objects.
Type: RefWrapper{},
}

func objectsForPaths(ctx context.Context, n iface.CoreAPI, paths []string) ([]cid.Cid, error) {
roots := make([]cid.Cid, len(paths))
func objectsForPaths(ctx context.Context, n iface.CoreAPI, paths []string) ([]ipld.Node, error) {
objects := make([]ipld.Node, len(paths))
for i, sp := range paths {
o, err := n.ResolvePath(ctx, path.New(sp))
o, err := n.ResolveNode(ctx, path.New(sp))
if err != nil {
return nil, err
}
roots[i] = o.Cid()
objects[i] = o
}
return roots, nil
return objects, nil
}

type RefWrapper struct {
Expand All @@ -185,7 +183,7 @@ type RefWrapper struct {

type RefWriter struct {
res cmds.ResponseEmitter
DAG ipld.NodeGetter
DAG ipld.DAGService
Ctx context.Context

Unique bool
Expand All @@ -196,11 +194,7 @@ type RefWriter struct {
}

// WriteRefs writes refs of the given object to the underlying writer.
func (rw *RefWriter) WriteRefs(c cid.Cid, enc cidenc.Encoder) (int, error) {
n, err := rw.DAG.Get(rw.Ctx, c)
if err != nil {
return 0, err
}
func (rw *RefWriter) WriteRefs(n ipld.Node, enc cidenc.Encoder) (int, error) {
return rw.writeRefsRecursive(n, 0, enc)
}

Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ require (
go.uber.org/multierr v1.1.0 // indirect
go4.org v0.0.0-20190313082347-94abd6928b1d // indirect
golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb
google.golang.org/appengine v1.4.0 // indirect
gopkg.in/cheggaaa/pb.v1 v1.0.28
gotest.tools/gotestsum v0.3.4
)
Expand Down

0 comments on commit 3ebcae7

Please sign in to comment.