Skip to content

Commit

Permalink
coreiface: updates for path name refactor
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
  • Loading branch information
magik6k committed Mar 26, 2019
1 parent 89b6650 commit 875f463
Show file tree
Hide file tree
Showing 22 changed files with 48 additions and 48 deletions.
6 changes: 3 additions & 3 deletions core/commands/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ on raw IPFS blocks. It outputs the following to stdout:
return err
}

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

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

// TODO: use batching coreapi when done
for _, b := range req.Arguments {
rp, err := api.ResolvePath(req.Context, path.ParsePath(b))
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
2 changes: 1 addition & 1 deletion core/commands/cat.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func cat(ctx context.Context, api iface.CoreAPI, paths []string, offset int64, m
return nil, 0, nil
}
for _, p := range paths {
f, err := api.Unixfs().Get(ctx, path.ParsePath(p))
f, err := api.Unixfs().Get(ctx, path.New(p))
if err != nil {
return nil, 0, err
}
Expand Down
4 changes: 2 additions & 2 deletions core/commands/dag/dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ format.
return err
}

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

rp, err := api.ResolvePath(req.Context, path.ParsePath(req.Arguments[0]))
rp, err := api.ResolvePath(req.Context, path.New(req.Arguments[0]))
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion core/commands/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,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/"):
return api.ResolveNode(ctx, path.ParsePath(p))
return api.ResolveNode(ctx, path.New(p))
default:
fsn, err := mfs.Lookup(node.FilesRoot, p)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion core/commands/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ may also specify the level of compression by specifying '-l=<1-9>'.
return err
}

p := path.ParsePath(req.Arguments[0])
p := path.New(req.Arguments[0])

file, err := api.Unixfs().Get(req.Context, p)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion core/commands/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ The JSON output contains type information.
}

for i, fpath := range paths {
results, err := api.Unixfs().Ls(req.Context, path.ParsePath(fpath),
results, err := api.Unixfs().Ls(req.Context, path.New(fpath),
options.Unixfs.ResolveChildren(resolveSize || resolveType))
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion core/commands/name/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ Alternatively, publish an <ipfs-path> using a valid PeerID (as listed by
opts = append(opts, options.Name.TTL(d))
}

p := path.ParsePath(req.Arguments[0])
p := path.New(req.Arguments[0])

if verifyExists, _ := req.Options[resolveOptionName].(bool); verifyExists {
_, err := api.ResolveNode(req.Context, p)
Expand Down
4 changes: 2 additions & 2 deletions core/commands/object/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ Example:
return err
}

pa := path.ParsePath(req.Arguments[0])
pb := path.ParsePath(req.Arguments[1])
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
8 changes: 4 additions & 4 deletions core/commands/object/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ is the raw data of the object.
return err
}

path := path.ParsePath(req.Arguments[0])
path := path.New(req.Arguments[0])

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

path := path.ParsePath(req.Arguments[0])
path := path.New(req.Arguments[0])

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

path := path.ParsePath(req.Arguments[0])
path := path.New(req.Arguments[0])

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

ns, err := api.Object().Stat(req.Context, path.ParsePath(req.Arguments[0]))
ns, err := api.Object().Stat(req.Context, path.New(req.Arguments[0]))
if err != nil {
return err
}
Expand Down
10 changes: 5 additions & 5 deletions core/commands/object/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ the limit will not be respected by the network.
return err
}

root := path.ParsePath(req.Arguments[0])
root := path.New(req.Arguments[0])

file, err := cmdenv.GetFileArg(req.Files.Entries())
if err != nil {
Expand Down Expand Up @@ -99,7 +99,7 @@ Example:
return err
}

root := path.ParsePath(req.Arguments[0])
root := path.New(req.Arguments[0])

file, err := cmdenv.GetFileArg(req.Files.Entries())
if err != nil {
Expand Down Expand Up @@ -139,7 +139,7 @@ Remove a Merkle-link from the given object and return the hash of the result.
return err
}

root := path.ParsePath(req.Arguments[0])
root := path.New(req.Arguments[0])

name := req.Arguments[1]
p, err := api.Object().RmLink(req.Context, root, name)
Expand Down Expand Up @@ -192,9 +192,9 @@ to a file containing 'bar', and returns the hash of the new object.
return err
}

root := path.ParsePath(req.Arguments[0])
root := path.New(req.Arguments[0])
name := req.Arguments[1]
child := path.ParsePath(req.Arguments[2])
child := path.New(req.Arguments[2])

create, _ := req.Options[createOptionName].(bool)
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions core/commands/pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ var addPinCmd = &cmds.Command{
func pinAddMany(ctx context.Context, api coreiface.CoreAPI, enc cidenc.Encoder, paths []string, recursive bool) ([]string, error) {
added := make([]string, len(paths))
for i, b := range paths {
rp, err := api.ResolvePath(ctx, path.ParsePath(b))
rp, err := api.ResolvePath(ctx, path.New(b))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -234,7 +234,7 @@ collected if needed. (By default, recursively. Use -r=false for direct pins.)

pins := make([]string, 0, len(req.Arguments))
for _, b := range req.Arguments {
rp, err := api.ResolvePath(req.Context, path.ParsePath(b))
rp, err := api.ResolvePath(req.Context, path.New(b))
if err != nil {
return err
}
Expand Down Expand Up @@ -408,8 +408,8 @@ new pin and removing the old one.

unpin, _ := req.Options[pinUnpinOptionName].(bool)

from := path.ParsePath(req.Arguments[0])
to := path.ParsePath(req.Arguments[1])
from := path.New(req.Arguments[0])
to := path.New(req.Arguments[1])

err = api.Pin().Update(req.Context, from, to, options.Pin.Unpin(unpin))
if err != nil {
Expand Down Expand Up @@ -498,7 +498,7 @@ func pinLsKeys(ctx context.Context, args []string, typeStr string, n *core.IpfsN
keys := make(map[cid.Cid]RefKeyObject)

for _, p := range args {
c, err := api.ResolvePath(ctx, path.ParsePath(p))
c, err := api.ResolvePath(ctx, path.New(p))
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion core/commands/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ Resolve the value of an IPFS DAG path:
}

// else, ipfs path or ipns with recursive flag
rp, err := api.ResolvePath(req.Context, path.ParsePath(name))
rp, err := api.ResolvePath(req.Context, path.New(name))
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion core/commands/unixfs/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ possible, please use 'ipfs ls' instead.
for _, p := range paths {
ctx := req.Context

merkleNode, err := api.ResolveNode(ctx, path.ParsePath(p))
merkleNode, err := api.ResolveNode(ctx, path.New(p))
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions core/coreapi/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
type BlockAPI CoreAPI

type BlockStat struct {
path path.ResolvedPath
path path.Resolved
size int
}

Expand Down Expand Up @@ -134,7 +134,7 @@ func (bs *BlockStat) Size() int {
return bs.size
}

func (bs *BlockStat) Path() path.ResolvedPath {
func (bs *BlockStat) Path() path.Resolved {
return bs.path
}

Expand Down
2 changes: 1 addition & 1 deletion core/coreapi/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (k *key) Name() string {

// Path returns the path of the key.
func (k *key) Path() path.Path {
return path.ParsePath(ipfspath.Join([]string{"/ipns", k.peerID.Pretty()}))
return path.New(ipfspath.Join([]string{"/ipns", k.peerID.Pretty()}))
}

// ID returns key PeerID
Expand Down
2 changes: 1 addition & 1 deletion core/coreapi/name.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (api *NameAPI) Search(ctx context.Context, name string, opts ...caopts.Name
defer close(out)
for res := range resolver.ResolveAsync(ctx, name, options.ResolveOpts...) {
select {
case out <- coreiface.IpnsResult{Path: path.ParsePath(res.Path.String()), Err: res.Err}:
case out <- coreiface.IpnsResult{Path: path.New(res.Path.String()), Err: res.Err}:
case <-ctx.Done():
return
}
Expand Down
12 changes: 6 additions & 6 deletions core/coreapi/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (api *ObjectAPI) New(ctx context.Context, opts ...caopts.ObjectNewOption) (
return n, nil
}

func (api *ObjectAPI) Put(ctx context.Context, src io.Reader, opts ...caopts.ObjectPutOption) (ipath.ResolvedPath, error) {
func (api *ObjectAPI) Put(ctx context.Context, src io.Reader, opts ...caopts.ObjectPutOption) (ipath.Resolved, error) {
options, err := caopts.ObjectPutOptions(opts...)
if err != nil {
return nil, err
Expand Down Expand Up @@ -194,7 +194,7 @@ func (api *ObjectAPI) Stat(ctx context.Context, path ipath.Path) (*coreiface.Obj
return out, nil
}

func (api *ObjectAPI) AddLink(ctx context.Context, base ipath.Path, name string, child ipath.Path, opts ...caopts.ObjectAddLinkOption) (ipath.ResolvedPath, error) {
func (api *ObjectAPI) AddLink(ctx context.Context, base ipath.Path, name string, child ipath.Path, opts ...caopts.ObjectAddLinkOption) (ipath.Resolved, error) {
options, err := caopts.ObjectAddLinkOptions(opts...)
if err != nil {
return nil, err
Expand Down Expand Up @@ -235,7 +235,7 @@ func (api *ObjectAPI) AddLink(ctx context.Context, base ipath.Path, name string,
return ipath.IpfsPath(nnode.Cid()), nil
}

func (api *ObjectAPI) RmLink(ctx context.Context, base ipath.Path, link string) (ipath.ResolvedPath, error) {
func (api *ObjectAPI) RmLink(ctx context.Context, base ipath.Path, link string) (ipath.Resolved, error) {
baseNd, err := api.core().ResolveNode(ctx, base)
if err != nil {
return nil, err
Expand All @@ -261,15 +261,15 @@ func (api *ObjectAPI) RmLink(ctx context.Context, base ipath.Path, link string)
return ipath.IpfsPath(nnode.Cid()), nil
}

func (api *ObjectAPI) AppendData(ctx context.Context, path ipath.Path, r io.Reader) (ipath.ResolvedPath, error) {
func (api *ObjectAPI) AppendData(ctx context.Context, path ipath.Path, r io.Reader) (ipath.Resolved, error) {
return api.patchData(ctx, path, r, true)
}

func (api *ObjectAPI) SetData(ctx context.Context, path ipath.Path, r io.Reader) (ipath.ResolvedPath, error) {
func (api *ObjectAPI) SetData(ctx context.Context, path ipath.Path, r io.Reader) (ipath.Resolved, error) {
return api.patchData(ctx, path, r, false)
}

func (api *ObjectAPI) patchData(ctx context.Context, path ipath.Path, r io.Reader, appendData bool) (ipath.ResolvedPath, error) {
func (api *ObjectAPI) patchData(ctx context.Context, path ipath.Path, r io.Reader, appendData bool) (ipath.Resolved, error) {
nd, err := api.core().ResolveNode(ctx, path)
if err != nil {
return nil, err
Expand Down
6 changes: 3 additions & 3 deletions core/coreapi/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ func (api *CoreAPI) ResolveNode(ctx context.Context, p path.Path) (ipld.Node, er

// ResolvePath resolves the path `p` using Unixfs resolver, returns the
// resolved path.
func (api *CoreAPI) ResolvePath(ctx context.Context, p path.Path) (path.ResolvedPath, error) {
if _, ok := p.(path.ResolvedPath); ok {
return p.(path.ResolvedPath), nil
func (api *CoreAPI) ResolvePath(ctx context.Context, p path.Path) (path.Resolved, error) {
if _, ok := p.(path.Resolved); ok {
return p.(path.Resolved), nil
}
if err := p.IsValid(); err != nil {
return nil, err
Expand Down
8 changes: 4 additions & 4 deletions core/coreapi/pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ type pinStatus struct {

// BadNode is used in PinVerifyRes
type badNode struct {
path path.ResolvedPath
path path.Resolved
err error
}

Expand All @@ -120,7 +120,7 @@ func (s *pinStatus) BadNodes() []coreiface.BadPinNode {
return s.badNodes
}

func (n *badNode) Path() path.ResolvedPath {
func (n *badNode) Path() path.Resolved {
return n.path
}

Expand Down Expand Up @@ -175,10 +175,10 @@ func (api *PinAPI) Verify(ctx context.Context) (<-chan coreiface.PinStatus, erro

type pinInfo struct {
pinType string
path path.ResolvedPath
path path.Resolved
}

func (p *pinInfo) Path() path.ResolvedPath {
func (p *pinInfo) Path() path.Resolved {
return p.path
}

Expand Down
2 changes: 1 addition & 1 deletion core/coreapi/unixfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type UnixfsAPI CoreAPI

// Add builds a merkledag node from a reader, adds it to the blockstore,
// and returns the key representing that node.
func (api *UnixfsAPI) Add(ctx context.Context, files files.Node, opts ...options.UnixfsAddOption) (path.ResolvedPath, error) {
func (api *UnixfsAPI) Add(ctx context.Context, files files.Node, opts ...options.UnixfsAddOption) (path.Resolved, error) {
settings, prefix, err := options.UnixfsAddOptions(opts...)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion core/corehttp/gateway_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr
ipnsHostname = true
}

parsedPath := ipath.ParsePath(urlPath)
parsedPath := ipath.New(urlPath)
if err := parsedPath.IsValid(); err != nil {
webError(w, "invalid ipfs path", err, http.StatusBadRequest)
return
Expand Down
2 changes: 1 addition & 1 deletion fuse/readonly/ipfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func TestIpfsStressRead(t *testing.T) {
defer wg.Done()

for i := 0; i < 2000; i++ {
item := ipath.ParsePath(paths[rand.Intn(len(paths))])
item := ipath.New(paths[rand.Intn(len(paths))])

relpath := strings.Replace(item.String(), item.Namespace(), "", 1)
fname := path.Join(mnt.Dir, relpath)
Expand Down

0 comments on commit 875f463

Please sign in to comment.