Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coreapi: Drop error from ParsePath #6122

Merged
merged 4 commits into from
Apr 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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