Skip to content

Commit 6338df4

Browse files
committed
refactor: return remainder from ResolvePath
1 parent 842dd81 commit 6338df4

File tree

22 files changed

+68
-58
lines changed

22 files changed

+68
-58
lines changed

client/rpc/apifile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const forwardSeekLimit = 1 << 14 // 16k
1717
func (api *UnixfsAPI) Get(ctx context.Context, p path.Path) (files.Node, error) {
1818
if p.Namespace().Mutable() { // use resolved path in case we are dealing with IPNS / MFS
1919
var err error
20-
p, err = api.core().ResolvePath(ctx, p)
20+
p, _, err = api.core().ResolvePath(ctx, p)
2121
if err != nil {
2222
return nil, err
2323
}

client/rpc/dht.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (api *DhtAPI) FindProviders(ctx context.Context, p path.Path, opts ...caopt
4242
return nil, err
4343
}
4444

45-
rp, err := api.core().ResolvePath(ctx, p)
45+
rp, _, err := api.core().ResolvePath(ctx, p)
4646
if err != nil {
4747
return nil, err
4848
}
@@ -98,7 +98,7 @@ func (api *DhtAPI) Provide(ctx context.Context, p path.Path, opts ...caopts.DhtP
9898
return err
9999
}
100100

101-
rp, err := api.core().ResolvePath(ctx, p)
101+
rp, _, err := api.core().ResolvePath(ctx, p)
102102
if err != nil {
103103
return err
104104
}

client/rpc/path.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,38 @@ import (
88
ipld "github.com/ipfs/go-ipld-format"
99
)
1010

11-
func (api *HttpApi) ResolvePath(ctx context.Context, p path.Path) (path.ImmutablePath, error) {
11+
func (api *HttpApi) ResolvePath(ctx context.Context, p path.Path) (path.ImmutablePath, []string, error) {
1212
var out struct {
1313
Cid cid.Cid
1414
RemPath string
1515
}
1616

17-
// TODO: this is hacky, fixing https://github.com/ipfs/go-ipfs/issues/5703 would help
18-
1917
var err error
2018
if p.Namespace() == path.IPNSNamespace {
2119
if p, err = api.Name().Resolve(ctx, p.String()); err != nil {
22-
return nil, err
20+
return nil, nil, err
2321
}
2422
}
2523

2624
if err := api.Request("dag/resolve", p.String()).Exec(ctx, &out); err != nil {
27-
return nil, err
25+
return nil, nil, err
2826
}
2927

3028
p, err = path.NewPathFromSegments(p.Namespace().String(), out.Cid.String(), out.RemPath)
3129
if err != nil {
32-
return nil, err
30+
return nil, nil, err
31+
}
32+
33+
imPath, err := path.NewImmutablePath(p)
34+
if err != nil {
35+
return nil, nil, err
3336
}
3437

35-
return path.NewImmutablePath(p)
38+
return imPath, path.StringToSegments(out.RemPath), nil
3639
}
3740

3841
func (api *HttpApi) ResolveNode(ctx context.Context, p path.Path) (ipld.Node, error) {
39-
rp, err := api.ResolvePath(ctx, p)
42+
rp, _, err := api.ResolvePath(ctx, p)
4043
if err != nil {
4144
return nil, err
4245
}

core/commands/block.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ It takes a list of CIDs to remove from the local datastore..
270270
return err
271271
}
272272

273-
rp, err := api.ResolvePath(req.Context, p)
273+
rp, _, err := api.ResolvePath(req.Context, p)
274274
if err != nil {
275275
return err
276276
}

core/commands/dag/get.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"io"
66

7+
"github.com/ipfs/boxo/path"
78
ipldlegacy "github.com/ipfs/go-ipld-legacy"
89
"github.com/ipfs/kubo/core/commands/cmdenv"
910
"github.com/ipfs/kubo/core/commands/cmdutils"
@@ -33,7 +34,7 @@ func dagGet(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) e
3334
return err
3435
}
3536

36-
rp, err := api.ResolvePath(req.Context, p)
37+
rp, remainder, err := api.ResolvePath(req.Context, p)
3738
if err != nil {
3839
return err
3940
}
@@ -50,8 +51,8 @@ func dagGet(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) e
5051

5152
finalNode := universal.(ipld.Node)
5253

53-
if len(rp.Remainder()) > 0 {
54-
remainderPath := ipld.ParsePath(rp.Remainder())
54+
if len(remainder) > 0 {
55+
remainderPath := ipld.ParsePath(path.SegmentsToString(remainder...))
5556

5657
finalNode, err = traversal.Get(finalNode, remainderPath)
5758
if err != nil {

core/commands/dag/resolve.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dagcmd
22

33
import (
4+
"github.com/ipfs/boxo/path"
45
"github.com/ipfs/kubo/core/commands/cmdenv"
56
"github.com/ipfs/kubo/core/commands/cmdutils"
67

@@ -18,13 +19,13 @@ func dagResolve(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environmen
1819
return err
1920
}
2021

21-
rp, err := api.ResolvePath(req.Context, p)
22+
rp, remainder, err := api.ResolvePath(req.Context, p)
2223
if err != nil {
2324
return err
2425
}
2526

2627
return cmds.EmitOnce(res, &ResolveOutput{
2728
Cid: rp.Cid(),
28-
RemPath: rp.Remainder(),
29+
RemPath: path.SegmentsToString(remainder...),
2930
})
3031
}

core/commands/dag/stat.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ func dagStat(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment)
3333
if err != nil {
3434
return err
3535
}
36-
rp, err := api.ResolvePath(req.Context, p)
36+
rp, remainder, err := api.ResolvePath(req.Context, p)
3737
if err != nil {
3838
return err
3939
}
40-
if len(rp.Remainder()) > 0 {
40+
if len(remainder) > 0 {
4141
return fmt.Errorf("cannot return size for anything other than a DAG with a root CID")
4242
}
4343

core/commands/object/object.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ multihash. Provided for legacy reasons. Use 'ipfs dag get' instead.
143143
return err
144144
}
145145

146-
rp, err := api.ResolvePath(req.Context, path)
146+
rp, _, err := api.ResolvePath(req.Context, path)
147147
if err != nil {
148148
return err
149149
}

core/commands/pin/pin.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ func pinAddMany(ctx context.Context, api coreiface.CoreAPI, enc cidenc.Encoder,
189189
return nil, err
190190
}
191191

192-
rp, err := api.ResolvePath(ctx, p)
192+
rp, _, err := api.ResolvePath(ctx, p)
193193
if err != nil {
194194
return nil, err
195195
}
@@ -252,7 +252,7 @@ ipfs pin ls -t indirect <cid>
252252
return err
253253
}
254254

255-
rp, err := api.ResolvePath(req.Context, p)
255+
rp, _, err := api.ResolvePath(req.Context, p)
256256
if err != nil {
257257
return err
258258
}
@@ -468,7 +468,7 @@ func pinLsKeys(req *cmds.Request, typeStr string, api coreiface.CoreAPI, emit fu
468468
return err
469469
}
470470

471-
rp, err := api.ResolvePath(req.Context, p)
471+
rp, _, err := api.ResolvePath(req.Context, p)
472472
if err != nil {
473473
return err
474474
}
@@ -594,11 +594,11 @@ pin.
594594
}
595595

596596
// Resolve the paths ahead of time so we can return the actual CIDs
597-
from, err := api.ResolvePath(req.Context, fromPath)
597+
from, _, err := api.ResolvePath(req.Context, fromPath)
598598
if err != nil {
599599
return err
600600
}
601-
to, err := api.ResolvePath(req.Context, toPath)
601+
to, _, err := api.ResolvePath(req.Context, toPath)
602602
if err != nil {
603603
return err
604604
}

core/commands/pin/remotepin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ NOTE: a comma-separated notation is supported in CLI for convenience:
162162
return err
163163
}
164164

165-
rp, err := api.ResolvePath(ctx, p)
165+
rp, _, err := api.ResolvePath(ctx, p)
166166
if err != nil {
167167
return err
168168
}

0 commit comments

Comments
 (0)