mirror of
https://github.com/ipfs/kubo.git
synced 2025-05-21 00:47:22 +08:00
coreiface: updates for path name refactor
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
This commit is contained in:

committed by
Steven Allen

parent
667b7f9927
commit
a54b64bede
@ -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 <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
|
||||
}
|
||||
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
Reference in New Issue
Block a user