Skip to content

Commit

Permalink
chore: update boxo for structification of ImmutablePath
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorropo authored and hacdias committed Oct 9, 2023
1 parent a7c6518 commit a5668d2
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 84 deletions.
24 changes: 12 additions & 12 deletions client/rpc/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (api *ObjectAPI) New(ctx context.Context, opts ...caopts.ObjectNewOption) (
func (api *ObjectAPI) Put(ctx context.Context, r io.Reader, opts ...caopts.ObjectPutOption) (path.ImmutablePath, error) {
options, err := caopts.ObjectPutOptions(opts...)
if err != nil {
return nil, err
return path.ImmutablePath{}, err
}

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

c, err := cid.Parse(out.Hash)
if err != nil {
return nil, err
return path.ImmutablePath{}, err
}

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

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

c, err := cid.Parse(out.Hash)
if err != nil {
return nil, err
return path.ImmutablePath{}, err
}

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

c, err := cid.Parse(out.Hash)
if err != nil {
return nil, err
return path.ImmutablePath{}, err
}

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

c, err := cid.Parse(out.Hash)
if err != nil {
return nil, err
return path.ImmutablePath{}, err
}

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

c, err := cid.Parse(out.Hash)
if err != nil {
return nil, err
return path.ImmutablePath{}, err
}

return path.FromCid(c), nil
Expand Down
8 changes: 4 additions & 4 deletions client/rpc/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ func (api *HttpApi) ResolvePath(ctx context.Context, p path.Path) (path.Immutabl
var err error
if p.Namespace() == path.IPNSNamespace {
if p, err = api.Name().Resolve(ctx, p.String()); err != nil {
return nil, nil, err
return path.ImmutablePath{}, nil, err
}
}

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

p, err = path.NewPathFromSegments(p.Namespace(), out.Cid.String(), out.RemPath)
if err != nil {
return nil, nil, err
return path.ImmutablePath{}, nil, err
}

imPath, err := path.NewImmutablePath(p)
if err != nil {
return nil, nil, err
return path.ImmutablePath{}, nil, err
}

return imPath, path.StringToSegments(out.RemPath), nil
Expand Down
18 changes: 9 additions & 9 deletions client/rpc/unixfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ type UnixfsAPI HttpApi
func (api *UnixfsAPI) Add(ctx context.Context, f files.Node, opts ...caopts.UnixfsAddOption) (path.ImmutablePath, error) {
options, _, err := caopts.UnixfsAddOptions(opts...)
if err != nil {
return nil, err
return path.ImmutablePath{}, err
}

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

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

version, err := api.core().loadRemoteVersion()
if err != nil {
return nil, err
return path.ImmutablePath{}, err
}
useEncodedAbsPaths := version.LT(encodedAbsolutePathVersion)
req.Body(files.NewMultiFileReader(d, false, useEncodedAbsPaths))

var out addEvent
resp, err := req.Send(ctx)
if err != nil {
return nil, err
return path.ImmutablePath{}, err
}
if resp.Error != nil {
return nil, resp.Error
return path.ImmutablePath{}, resp.Error
}
defer resp.Output.Close()
dec := json.NewDecoder(resp.Output)
Expand All @@ -88,7 +88,7 @@ loop:
case io.EOF:
break loop
default:
return nil, err
return path.ImmutablePath{}, err
}
out = evt

Expand All @@ -102,7 +102,7 @@ loop:
if out.Hash != "" {
c, err := cid.Parse(out.Hash)
if err != nil {
return nil, err
return path.ImmutablePath{}, err
}

ifevt.Path = path.FromCid(c)
Expand All @@ -111,14 +111,14 @@ loop:
select {
case options.Events <- ifevt:
case <-ctx.Done():
return nil, ctx.Err()
return path.ImmutablePath{}, ctx.Err()
}
}
}

c, err := cid.Parse(out.Hash)
if err != nil {
return nil, err
return path.ImmutablePath{}, err
}

return path.FromCid(c), nil
Expand Down
13 changes: 7 additions & 6 deletions core/commands/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"io"
"os"
"path"
gopath "path"
"strings"

"github.com/ipfs/kubo/core/commands/cmdenv"
Expand All @@ -15,6 +15,7 @@ import (
"github.com/ipfs/boxo/coreiface/options"
"github.com/ipfs/boxo/files"
mfs "github.com/ipfs/boxo/mfs"
"github.com/ipfs/boxo/path"
cmds "github.com/ipfs/go-ipfs-cmds"
ipld "github.com/ipfs/go-ipld-format"
mh "github.com/multiformats/go-multihash"
Expand Down Expand Up @@ -301,7 +302,7 @@ See 'dag export' and 'dag import' for more information.
return
}
// if MFS destination is a dir, append filename to the dir path
toFilesDst += path.Base(addit.Name())
toFilesDst += gopath.Base(addit.Name())
}

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

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

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

h := ""
if output.Path != nil {
if (output.Path != path.ImmutablePath{}) {
h = enc.Encode(output.Path.RootCid())
}

if !dir && addit.Name() != "" {
output.Name = addit.Name()
} else {
output.Name = path.Join(addit.Name(), output.Name)
output.Name = gopath.Join(addit.Name(), output.Name)
}

if err := res.Emit(&AddEvent{
Expand Down
5 changes: 3 additions & 2 deletions core/commands/object/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"

"github.com/ipfs/boxo/ipld/merkledag/dagutils"
"github.com/ipfs/boxo/path"
cmds "github.com/ipfs/go-ipfs-cmds"

cmdenv "github.com/ipfs/kubo/core/commands/cmdenv"
Expand Down Expand Up @@ -82,11 +83,11 @@ Example:
Path: change.Path,
}

if change.Before != nil {
if (change.Before != path.ImmutablePath{}) {
out[i].Before = change.Before.RootCid()
}

if change.After != nil {
if (change.After != path.ImmutablePath{}) {
out[i].After = change.After.RootCid()
}
}
Expand Down
Loading

0 comments on commit a5668d2

Please sign in to comment.