Skip to content

Commit

Permalink
Merge pull request #6122 from ipfs/feat/coreapi/path-errs
Browse files Browse the repository at this point in the history
coreapi: Drop error from ParsePath
  • Loading branch information
Stebalien authored Apr 17, 2019
2 parents 88e34fe + 21c6e07 commit c8e34bc
Show file tree
Hide file tree
Showing 28 changed files with 129 additions and 239 deletions.
4 changes: 2 additions & 2 deletions assets/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (

cid "github.com/ipfs/go-cid"
files "github.com/ipfs/go-ipfs-files"
iface "github.com/ipfs/interface-go-ipfs-core"
options "github.com/ipfs/interface-go-ipfs-core/options"
"github.com/ipfs/interface-go-ipfs-core/path"

// this import keeps gx from thinking the dep isn't used
_ "github.com/ipfs/dir-index-html"
Expand Down Expand Up @@ -57,7 +57,7 @@ func addAssetList(nd *core.IpfsNode, l []string) (cid.Cid, error) {
return cid.Cid{}, err
}

basePath := iface.IpfsPath(dirb.Cid())
basePath := path.IpfsPath(dirb.Cid())

for _, p := range l {
d, err := Asset(p)
Expand Down
26 changes: 4 additions & 22 deletions core/commands/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (

cmdkit "github.com/ipfs/go-ipfs-cmdkit"
cmds "github.com/ipfs/go-ipfs-cmds"
coreiface "github.com/ipfs/interface-go-ipfs-core"
options "github.com/ipfs/interface-go-ipfs-core/options"
path "github.com/ipfs/interface-go-ipfs-core/path"
mh "github.com/multiformats/go-multihash"
)

Expand Down Expand Up @@ -65,12 +65,7 @@ on raw IPFS blocks. It outputs the following to stdout:
return err
}

p, err := coreiface.ParsePath(req.Arguments[0])
if err != nil {
return err
}

b, err := api.Block().Stat(req.Context, p)
b, err := api.Block().Stat(req.Context, path.New(req.Arguments[0]))
if err != nil {
return err
}
Expand Down Expand Up @@ -107,12 +102,7 @@ It outputs to stdout, and <key> is a base58 encoded multihash.
return err
}

p, err := coreiface.ParsePath(req.Arguments[0])
if err != nil {
return err
}

r, err := api.Block().Get(req.Context, p)
r, err := api.Block().Get(req.Context, path.New(req.Arguments[0]))
if err != nil {
return err
}
Expand Down Expand Up @@ -234,15 +224,7 @@ It takes a list of base58 encoded multihashes to remove.

// TODO: use batching coreapi when done
for _, b := range req.Arguments {
p, err := coreiface.ParsePath(b)
if err != nil {
return err
}

rp, err := api.ResolvePath(req.Context, p)
if err != nil {
return err
}
rp, err := api.ResolvePath(req.Context, path.New(b))

err = api.Block().Rm(req.Context, rp, options.Block.Force(force))
if err != nil {
Expand Down
8 changes: 2 additions & 6 deletions core/commands/cat.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
cmds "github.com/ipfs/go-ipfs-cmds"
"github.com/ipfs/go-ipfs-files"
"github.com/ipfs/interface-go-ipfs-core"
"github.com/ipfs/interface-go-ipfs-core/path"
)

const (
Expand Down Expand Up @@ -118,12 +119,7 @@ func cat(ctx context.Context, api iface.CoreAPI, paths []string, offset int64, m
return nil, 0, nil
}
for _, p := range paths {
fpath, err := iface.ParsePath(p)
if err != nil {
return nil, 0, err
}

f, err := api.Unixfs().Get(ctx, fpath)
f, err := api.Unixfs().Get(ctx, path.New(p))
if err != nil {
return nil, 0, err
}
Expand Down
20 changes: 5 additions & 15 deletions core/commands/dag/dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
cmds "github.com/ipfs/go-ipfs-cmds"
files "github.com/ipfs/go-ipfs-files"
ipld "github.com/ipfs/go-ipld-format"
path "github.com/ipfs/go-path"
iface "github.com/ipfs/interface-go-ipfs-core"
ipfspath "github.com/ipfs/go-path"
path "github.com/ipfs/interface-go-ipfs-core/path"
mh "github.com/multiformats/go-multihash"
)

Expand Down Expand Up @@ -160,12 +160,7 @@ format.
return err
}

p, err := iface.ParsePath(req.Arguments[0])
if err != nil {
return err
}

rp, err := api.ResolvePath(req.Context, p)
rp, err := api.ResolvePath(req.Context, path.New(req.Arguments[0]))
if err != nil {
return err
}
Expand Down Expand Up @@ -205,12 +200,7 @@ var DagResolveCmd = &cmds.Command{
return err
}

p, err := iface.ParsePath(req.Arguments[0])
if err != nil {
return err
}

rp, err := api.ResolvePath(req.Context, p)
rp, err := api.ResolvePath(req.Context, path.New(req.Arguments[0]))
if err != nil {
return err
}
Expand Down Expand Up @@ -243,7 +233,7 @@ var DagResolveCmd = &cmds.Command{
}
p := enc.Encode(out.Cid)
if out.RemPath != "" {
p = path.Join([]string{p, out.RemPath})
p = ipfspath.Join([]string{p, out.RemPath})
}

fmt.Fprint(w, p)
Expand Down
8 changes: 2 additions & 6 deletions core/commands/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/ipfs/go-mfs"
ft "github.com/ipfs/go-unixfs"
"github.com/ipfs/interface-go-ipfs-core"
path "github.com/ipfs/interface-go-ipfs-core/path"
mh "github.com/multiformats/go-multihash"
)

Expand Down Expand Up @@ -363,12 +364,7 @@ var filesCpCmd = &cmds.Command{
func getNodeFromPath(ctx context.Context, node *core.IpfsNode, api iface.CoreAPI, p string) (ipld.Node, error) {
switch {
case strings.HasPrefix(p, "/ipfs/"):
np, err := iface.ParsePath(p)
if err != nil {
return nil, err
}

return api.ResolveNode(ctx, np)
return api.ResolveNode(ctx, path.New(p))
default:
fsn, err := mfs.Lookup(node.FilesRoot, p)
if err != nil {
Expand Down
13 changes: 5 additions & 8 deletions core/commands/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"fmt"
"io"
"os"
"path"
gopath "path"
"path/filepath"
"strings"

Expand All @@ -17,7 +17,7 @@ import (
cmdkit "github.com/ipfs/go-ipfs-cmdkit"
cmds "github.com/ipfs/go-ipfs-cmds"
files "github.com/ipfs/go-ipfs-files"
iface "github.com/ipfs/interface-go-ipfs-core"
"github.com/ipfs/interface-go-ipfs-core/path"
"github.com/whyrusleeping/tar-utils"
"gopkg.in/cheggaaa/pb.v1"
)
Expand Down Expand Up @@ -71,10 +71,7 @@ may also specify the level of compression by specifying '-l=<1-9>'.
return err
}

p, err := iface.ParsePath(req.Arguments[0])
if err != nil {
return err
}
p := path.New(req.Arguments[0])

file, err := api.Unixfs().Get(req.Context, p)
if err != nil {
Expand Down Expand Up @@ -267,8 +264,8 @@ func (i *identityWriteCloser) Close() error {
}

func fileArchive(f files.Node, name string, archive bool, compression int) (io.Reader, error) {
cleaned := path.Clean(name)
_, filename := path.Split(cleaned)
cleaned := gopath.Clean(name)
_, filename := gopath.Split(cleaned)

// need to connect a writer to a reader
piper, pipew := io.Pipe()
Expand Down
8 changes: 2 additions & 6 deletions core/commands/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
unixfs_pb "github.com/ipfs/go-unixfs/pb"
iface "github.com/ipfs/interface-go-ipfs-core"
options "github.com/ipfs/interface-go-ipfs-core/options"
path "github.com/ipfs/interface-go-ipfs-core/path"
)

// LsLink contains printable data for a single ipld link in ls output
Expand Down Expand Up @@ -131,12 +132,7 @@ The JSON output contains type information.
}

for i, fpath := range paths {
p, err := iface.ParsePath(fpath)
if err != nil {
return err
}

results, err := api.Unixfs().Ls(req.Context, p,
results, err := api.Unixfs().Ls(req.Context, path.New(fpath),
options.Unixfs.ResolveChildren(resolveSize || resolveType))
if err != nil {
return err
Expand Down
6 changes: 2 additions & 4 deletions core/commands/name/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
cmds "github.com/ipfs/go-ipfs-cmds"
iface "github.com/ipfs/interface-go-ipfs-core"
options "github.com/ipfs/interface-go-ipfs-core/options"
path "github.com/ipfs/interface-go-ipfs-core/path"
)

var (
Expand Down Expand Up @@ -112,10 +113,7 @@ Alternatively, publish an <ipfs-path> using a valid PeerID (as listed by
opts = append(opts, options.Name.TTL(d))
}

p, err := iface.ParsePath(req.Arguments[0])
if err != nil {
return err
}
p := path.New(req.Arguments[0])

if verifyExists, _ := req.Options[resolveOptionName].(bool); verifyExists {
_, err := api.ResolveNode(req.Context, p)
Expand Down
16 changes: 3 additions & 13 deletions core/commands/object/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

cmdkit "github.com/ipfs/go-ipfs-cmdkit"
cmds "github.com/ipfs/go-ipfs-cmds"
coreiface "github.com/ipfs/interface-go-ipfs-core"
path "github.com/ipfs/interface-go-ipfs-core/path"
)

const (
Expand Down Expand Up @@ -60,18 +60,8 @@ Example:
return err
}

a := req.Arguments[0]
b := req.Arguments[1]

pa, err := coreiface.ParsePath(a)
if err != nil {
return err
}

pb, err := coreiface.ParsePath(b)
if err != nil {
return err
}
pa := path.New(req.Arguments[0])
pb := path.New(req.Arguments[1])

changes, err := api.Object().Diff(req.Context, pa, pb)
if err != nil {
Expand Down
24 changes: 5 additions & 19 deletions core/commands/object/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
"github.com/ipfs/go-ipfs-cmds"
ipld "github.com/ipfs/go-ipld-format"
dag "github.com/ipfs/go-merkledag"
coreiface "github.com/ipfs/interface-go-ipfs-core"
"github.com/ipfs/interface-go-ipfs-core/options"
path "github.com/ipfs/interface-go-ipfs-core/path"
)

type Node struct {
Expand Down Expand Up @@ -91,10 +91,7 @@ is the raw data of the object.
return err
}

path, err := coreiface.ParsePath(req.Arguments[0])
if err != nil {
return err
}
path := path.New(req.Arguments[0])

data, err := api.Object().Data(req.Context, path)
if err != nil {
Expand Down Expand Up @@ -133,10 +130,7 @@ multihash.
return err
}

path, err := coreiface.ParsePath(req.Arguments[0])
if err != nil {
return err
}
path := path.New(req.Arguments[0])

rp, err := api.ResolvePath(req.Context, path)
if err != nil {
Expand Down Expand Up @@ -228,10 +222,7 @@ Supported values are:
return err
}

path, err := coreiface.ParsePath(req.Arguments[0])
if err != nil {
return err
}
path := path.New(req.Arguments[0])

datafieldenc, _ := req.Options[encodingOptionName].(string)
if err != nil {
Expand Down Expand Up @@ -323,12 +314,7 @@ var ObjectStatCmd = &cmds.Command{
return err
}

path, err := coreiface.ParsePath(req.Arguments[0])
if err != nil {
return err
}

ns, err := api.Object().Stat(req.Context, path)
ns, err := api.Object().Stat(req.Context, path.New(req.Arguments[0]))
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit c8e34bc

Please sign in to comment.