diff --git a/core/commands/block.go b/core/commands/block.go index 9d4be8f72..796ce72e8 100644 --- a/core/commands/block.go +++ b/core/commands/block.go @@ -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 } @@ -102,7 +102,7 @@ It outputs to stdout, and 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 } @@ -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 { diff --git a/core/commands/cat.go b/core/commands/cat.go index 15abfa232..1032523b5 100644 --- a/core/commands/cat.go +++ b/core/commands/cat.go @@ -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 } diff --git a/core/commands/dag/dag.go b/core/commands/dag/dag.go index d1e948b69..f8287578a 100644 --- a/core/commands/dag/dag.go +++ b/core/commands/dag/dag.go @@ -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 } @@ -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 } diff --git a/core/commands/files.go b/core/commands/files.go index c7892d701..700a78bc7 100644 --- a/core/commands/files.go +++ b/core/commands/files.go @@ -364,7 +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/"): - 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 { diff --git a/core/commands/get.go b/core/commands/get.go index b849ac0fd..8dfc7359e 100644 --- a/core/commands/get.go +++ b/core/commands/get.go @@ -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 { diff --git a/core/commands/ls.go b/core/commands/ls.go index a675c6742..c755e25d5 100644 --- a/core/commands/ls.go +++ b/core/commands/ls.go @@ -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 diff --git a/core/commands/name/publish.go b/core/commands/name/publish.go index 04a77f18c..b2643dcf4 100644 --- a/core/commands/name/publish.go +++ b/core/commands/name/publish.go @@ -113,7 +113,7 @@ Alternatively, publish an 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) diff --git a/core/commands/object/diff.go b/core/commands/object/diff.go index b1c1e6546..166035ff4 100644 --- a/core/commands/object/diff.go +++ b/core/commands/object/diff.go @@ -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 { diff --git a/core/commands/object/object.go b/core/commands/object/object.go index b636c601c..dc59b61da 100644 --- a/core/commands/object/object.go +++ b/core/commands/object/object.go @@ -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 { @@ -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 { @@ -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 { @@ -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 } diff --git a/core/commands/object/patch.go b/core/commands/object/patch.go index 88972d746..8b55a70ea 100644 --- a/core/commands/object/patch.go +++ b/core/commands/object/patch.go @@ -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 { @@ -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 { @@ -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) @@ -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 { diff --git a/core/commands/pin.go b/core/commands/pin.go index 3b64d96a6..ba594de7d 100644 --- a/core/commands/pin.go +++ b/core/commands/pin.go @@ -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 } @@ -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 } @@ -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 { @@ -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 } diff --git a/core/commands/resolve.go b/core/commands/resolve.go index b25acce09..6de05e1f2 100644 --- a/core/commands/resolve.go +++ b/core/commands/resolve.go @@ -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 } diff --git a/core/commands/unixfs/ls.go b/core/commands/unixfs/ls.go index 4d8f3cff8..2ca71ccb0 100644 --- a/core/commands/unixfs/ls.go +++ b/core/commands/unixfs/ls.go @@ -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 } diff --git a/core/coreapi/block.go b/core/coreapi/block.go index 945c31db4..79b89ed02 100644 --- a/core/coreapi/block.go +++ b/core/coreapi/block.go @@ -20,7 +20,7 @@ import ( type BlockAPI CoreAPI type BlockStat struct { - path path.ResolvedPath + path path.Resolved size int } @@ -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 } diff --git a/core/coreapi/key.go b/core/coreapi/key.go index 002ccba85..4fea3c5d4 100644 --- a/core/coreapi/key.go +++ b/core/coreapi/key.go @@ -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 diff --git a/core/coreapi/name.go b/core/coreapi/name.go index 5a627e414..43ed78b9f 100644 --- a/core/coreapi/name.go +++ b/core/coreapi/name.go @@ -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 } diff --git a/core/coreapi/object.go b/core/coreapi/object.go index c9829e2aa..7cbd480c5 100644 --- a/core/coreapi/object.go +++ b/core/coreapi/object.go @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/core/coreapi/path.go b/core/coreapi/path.go index c6e65322f..4c7837f36 100644 --- a/core/coreapi/path.go +++ b/core/coreapi/path.go @@ -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 diff --git a/core/coreapi/pin.go b/core/coreapi/pin.go index f8b8b0f75..bd2663f03 100644 --- a/core/coreapi/pin.go +++ b/core/coreapi/pin.go @@ -108,7 +108,7 @@ type pinStatus struct { // BadNode is used in PinVerifyRes type badNode struct { - path path.ResolvedPath + path path.Resolved err error } @@ -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 } @@ -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 } diff --git a/core/coreapi/unixfs.go b/core/coreapi/unixfs.go index fa036cad4..e8702837f 100644 --- a/core/coreapi/unixfs.go +++ b/core/coreapi/unixfs.go @@ -30,7 +30,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 diff --git a/core/corehttp/gateway_handler.go b/core/corehttp/gateway_handler.go index d9bb818e1..cdbcce594 100644 --- a/core/corehttp/gateway_handler.go +++ b/core/corehttp/gateway_handler.go @@ -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 diff --git a/fuse/readonly/ipfs_test.go b/fuse/readonly/ipfs_test.go index 41c5a84bb..3f03779ad 100644 --- a/fuse/readonly/ipfs_test.go +++ b/fuse/readonly/ipfs_test.go @@ -184,7 +184,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)