Skip to content

Commit a5668d2

Browse files
Jorropohacdias
authored andcommitted
chore: update boxo for structification of ImmutablePath
1 parent a7c6518 commit a5668d2

File tree

14 files changed

+86
-84
lines changed

14 files changed

+86
-84
lines changed

client/rpc/object.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (api *ObjectAPI) New(ctx context.Context, opts ...caopts.ObjectNewOption) (
4343
func (api *ObjectAPI) Put(ctx context.Context, r io.Reader, opts ...caopts.ObjectPutOption) (path.ImmutablePath, error) {
4444
options, err := caopts.ObjectPutOptions(opts...)
4545
if err != nil {
46-
return nil, err
46+
return path.ImmutablePath{}, err
4747
}
4848

4949
var out objectOut
@@ -54,12 +54,12 @@ func (api *ObjectAPI) Put(ctx context.Context, r io.Reader, opts ...caopts.Objec
5454
FileBody(r).
5555
Exec(ctx, &out)
5656
if err != nil {
57-
return nil, err
57+
return path.ImmutablePath{}, err
5858
}
5959

6060
c, err := cid.Parse(out.Hash)
6161
if err != nil {
62-
return nil, err
62+
return path.ImmutablePath{}, err
6363
}
6464

6565
return path.FromCid(c), nil
@@ -156,20 +156,20 @@ func (api *ObjectAPI) Stat(ctx context.Context, p path.Path) (*iface.ObjectStat,
156156
func (api *ObjectAPI) AddLink(ctx context.Context, base path.Path, name string, child path.Path, opts ...caopts.ObjectAddLinkOption) (path.ImmutablePath, error) {
157157
options, err := caopts.ObjectAddLinkOptions(opts...)
158158
if err != nil {
159-
return nil, err
159+
return path.ImmutablePath{}, err
160160
}
161161

162162
var out objectOut
163163
err = api.core().Request("object/patch/add-link", base.String(), name, child.String()).
164164
Option("create", options.Create).
165165
Exec(ctx, &out)
166166
if err != nil {
167-
return nil, err
167+
return path.ImmutablePath{}, err
168168
}
169169

170170
c, err := cid.Parse(out.Hash)
171171
if err != nil {
172-
return nil, err
172+
return path.ImmutablePath{}, err
173173
}
174174

175175
return path.FromCid(c), nil
@@ -180,12 +180,12 @@ func (api *ObjectAPI) RmLink(ctx context.Context, base path.Path, link string) (
180180
err := api.core().Request("object/patch/rm-link", base.String(), link).
181181
Exec(ctx, &out)
182182
if err != nil {
183-
return nil, err
183+
return path.ImmutablePath{}, err
184184
}
185185

186186
c, err := cid.Parse(out.Hash)
187187
if err != nil {
188-
return nil, err
188+
return path.ImmutablePath{}, err
189189
}
190190

191191
return path.FromCid(c), nil
@@ -197,12 +197,12 @@ func (api *ObjectAPI) AppendData(ctx context.Context, p path.Path, r io.Reader)
197197
FileBody(r).
198198
Exec(ctx, &out)
199199
if err != nil {
200-
return nil, err
200+
return path.ImmutablePath{}, err
201201
}
202202

203203
c, err := cid.Parse(out.Hash)
204204
if err != nil {
205-
return nil, err
205+
return path.ImmutablePath{}, err
206206
}
207207

208208
return path.FromCid(c), nil
@@ -214,12 +214,12 @@ func (api *ObjectAPI) SetData(ctx context.Context, p path.Path, r io.Reader) (pa
214214
FileBody(r).
215215
Exec(ctx, &out)
216216
if err != nil {
217-
return nil, err
217+
return path.ImmutablePath{}, err
218218
}
219219

220220
c, err := cid.Parse(out.Hash)
221221
if err != nil {
222-
return nil, err
222+
return path.ImmutablePath{}, err
223223
}
224224

225225
return path.FromCid(c), nil

client/rpc/path.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@ func (api *HttpApi) ResolvePath(ctx context.Context, p path.Path) (path.Immutabl
1717
var err error
1818
if p.Namespace() == path.IPNSNamespace {
1919
if p, err = api.Name().Resolve(ctx, p.String()); err != nil {
20-
return nil, nil, err
20+
return path.ImmutablePath{}, nil, err
2121
}
2222
}
2323

2424
if err := api.Request("dag/resolve", p.String()).Exec(ctx, &out); err != nil {
25-
return nil, nil, err
25+
return path.ImmutablePath{}, nil, err
2626
}
2727

2828
p, err = path.NewPathFromSegments(p.Namespace(), out.Cid.String(), out.RemPath)
2929
if err != nil {
30-
return nil, nil, err
30+
return path.ImmutablePath{}, nil, err
3131
}
3232

3333
imPath, err := path.NewImmutablePath(p)
3434
if err != nil {
35-
return nil, nil, err
35+
return path.ImmutablePath{}, nil, err
3636
}
3737

3838
return imPath, path.StringToSegments(out.RemPath), nil

client/rpc/unixfs.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ type UnixfsAPI HttpApi
2929
func (api *UnixfsAPI) Add(ctx context.Context, f files.Node, opts ...caopts.UnixfsAddOption) (path.ImmutablePath, error) {
3030
options, _, err := caopts.UnixfsAddOptions(opts...)
3131
if err != nil {
32-
return nil, err
32+
return path.ImmutablePath{}, err
3333
}
3434

3535
mht, ok := mh.Codes[options.MhType]
3636
if !ok {
37-
return nil, fmt.Errorf("unknowm mhType %d", options.MhType)
37+
return path.ImmutablePath{}, fmt.Errorf("unknowm mhType %d", options.MhType)
3838
}
3939

4040
req := api.core().Request("add").
@@ -65,18 +65,18 @@ func (api *UnixfsAPI) Add(ctx context.Context, f files.Node, opts ...caopts.Unix
6565

6666
version, err := api.core().loadRemoteVersion()
6767
if err != nil {
68-
return nil, err
68+
return path.ImmutablePath{}, err
6969
}
7070
useEncodedAbsPaths := version.LT(encodedAbsolutePathVersion)
7171
req.Body(files.NewMultiFileReader(d, false, useEncodedAbsPaths))
7272

7373
var out addEvent
7474
resp, err := req.Send(ctx)
7575
if err != nil {
76-
return nil, err
76+
return path.ImmutablePath{}, err
7777
}
7878
if resp.Error != nil {
79-
return nil, resp.Error
79+
return path.ImmutablePath{}, resp.Error
8080
}
8181
defer resp.Output.Close()
8282
dec := json.NewDecoder(resp.Output)
@@ -88,7 +88,7 @@ loop:
8888
case io.EOF:
8989
break loop
9090
default:
91-
return nil, err
91+
return path.ImmutablePath{}, err
9292
}
9393
out = evt
9494

@@ -102,7 +102,7 @@ loop:
102102
if out.Hash != "" {
103103
c, err := cid.Parse(out.Hash)
104104
if err != nil {
105-
return nil, err
105+
return path.ImmutablePath{}, err
106106
}
107107

108108
ifevt.Path = path.FromCid(c)
@@ -111,14 +111,14 @@ loop:
111111
select {
112112
case options.Events <- ifevt:
113113
case <-ctx.Done():
114-
return nil, ctx.Err()
114+
return path.ImmutablePath{}, ctx.Err()
115115
}
116116
}
117117
}
118118

119119
c, err := cid.Parse(out.Hash)
120120
if err != nil {
121-
return nil, err
121+
return path.ImmutablePath{}, err
122122
}
123123

124124
return path.FromCid(c), nil

core/commands/add.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"fmt"
66
"io"
77
"os"
8-
"path"
8+
gopath "path"
99
"strings"
1010

1111
"github.com/ipfs/kubo/core/commands/cmdenv"
@@ -15,6 +15,7 @@ import (
1515
"github.com/ipfs/boxo/coreiface/options"
1616
"github.com/ipfs/boxo/files"
1717
mfs "github.com/ipfs/boxo/mfs"
18+
"github.com/ipfs/boxo/path"
1819
cmds "github.com/ipfs/go-ipfs-cmds"
1920
ipld "github.com/ipfs/go-ipld-format"
2021
mh "github.com/multiformats/go-multihash"
@@ -301,7 +302,7 @@ See 'dag export' and 'dag import' for more information.
301302
return
302303
}
303304
// if MFS destination is a dir, append filename to the dir path
304-
toFilesDst += path.Base(addit.Name())
305+
toFilesDst += gopath.Base(addit.Name())
305306
}
306307

307308
// error if we try to overwrite a preexisting file destination
@@ -310,9 +311,9 @@ See 'dag export' and 'dag import' for more information.
310311
return
311312
}
312313

313-
_, err = mfs.Lookup(ipfsNode.FilesRoot, path.Dir(toFilesDst))
314+
_, err = mfs.Lookup(ipfsNode.FilesRoot, gopath.Dir(toFilesDst))
314315
if err != nil {
315-
errCh <- fmt.Errorf("%s: MFS destination parent %q %q does not exist: %w", toFilesOptionName, toFilesDst, path.Dir(toFilesDst), err)
316+
errCh <- fmt.Errorf("%s: MFS destination parent %q %q does not exist: %w", toFilesOptionName, toFilesDst, gopath.Dir(toFilesDst), err)
316317
return
317318
}
318319

@@ -339,14 +340,14 @@ See 'dag export' and 'dag import' for more information.
339340
}
340341

341342
h := ""
342-
if output.Path != nil {
343+
if (output.Path != path.ImmutablePath{}) {
343344
h = enc.Encode(output.Path.RootCid())
344345
}
345346

346347
if !dir && addit.Name() != "" {
347348
output.Name = addit.Name()
348349
} else {
349-
output.Name = path.Join(addit.Name(), output.Name)
350+
output.Name = gopath.Join(addit.Name(), output.Name)
350351
}
351352

352353
if err := res.Emit(&AddEvent{

core/commands/object/diff.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"io"
66

77
"github.com/ipfs/boxo/ipld/merkledag/dagutils"
8+
"github.com/ipfs/boxo/path"
89
cmds "github.com/ipfs/go-ipfs-cmds"
910

1011
cmdenv "github.com/ipfs/kubo/core/commands/cmdenv"
@@ -82,11 +83,11 @@ Example:
8283
Path: change.Path,
8384
}
8485

85-
if change.Before != nil {
86+
if (change.Before != path.ImmutablePath{}) {
8687
out[i].Before = change.Before.RootCid()
8788
}
8889

89-
if change.After != nil {
90+
if (change.After != path.ImmutablePath{}) {
9091
out[i].After = change.After.RootCid()
9192
}
9293
}

0 commit comments

Comments
 (0)