mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 10:27:46 +08:00
coreapi: Update path error handling
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
This commit is contained in:
parent
88e34fec44
commit
2e77df04ca
@ -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, coreiface.ParsePath(req.Arguments[0]))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -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, coreiface.ParsePath(req.Arguments[0]))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -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, coreiface.ParsePath(b))
|
||||
|
||||
err = api.Block().Rm(req.Context, rp, options.Block.Force(force))
|
||||
if err != nil {
|
||||
|
||||
@ -118,12 +118,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, iface.ParsePath(p))
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
@ -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, iface.ParsePath(req.Arguments[0]))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -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, iface.ParsePath(req.Arguments[0]))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -363,12 +363,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, iface.ParsePath(p))
|
||||
default:
|
||||
fsn, err := mfs.Lookup(node.FilesRoot, p)
|
||||
if err != nil {
|
||||
|
||||
@ -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 := iface.ParsePath(req.Arguments[0])
|
||||
|
||||
file, err := api.Unixfs().Get(req.Context, p)
|
||||
if err != nil {
|
||||
|
||||
@ -131,12 +131,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, iface.ParsePath(fpath),
|
||||
options.Unixfs.ResolveChildren(resolveSize || resolveType))
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@ -112,10 +112,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 := iface.ParsePath(req.Arguments[0])
|
||||
|
||||
if verifyExists, _ := req.Options[resolveOptionName].(bool); verifyExists {
|
||||
_, err := api.ResolveNode(req.Context, p)
|
||||
|
||||
@ -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 := coreiface.ParsePath(req.Arguments[0])
|
||||
pb := coreiface.ParsePath(req.Arguments[1])
|
||||
|
||||
changes, err := api.Object().Diff(req.Context, pa, pb)
|
||||
if err != nil {
|
||||
|
||||
@ -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 := coreiface.ParsePath(req.Arguments[0])
|
||||
|
||||
data, err := api.Object().Data(req.Context, path)
|
||||
if err != nil {
|
||||
@ -133,10 +130,7 @@ multihash.
|
||||
return err
|
||||
}
|
||||
|
||||
path, err := coreiface.ParsePath(req.Arguments[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
path := coreiface.ParsePath(req.Arguments[0])
|
||||
|
||||
rp, err := api.ResolvePath(req.Context, path)
|
||||
if err != nil {
|
||||
@ -228,10 +222,7 @@ Supported values are:
|
||||
return err
|
||||
}
|
||||
|
||||
path, err := coreiface.ParsePath(req.Arguments[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
path := coreiface.ParsePath(req.Arguments[0])
|
||||
|
||||
datafieldenc, _ := req.Options[encodingOptionName].(string)
|
||||
if err != nil {
|
||||
@ -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, coreiface.ParsePath(req.Arguments[0]))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -55,10 +55,7 @@ the limit will not be respected by the network.
|
||||
return err
|
||||
}
|
||||
|
||||
root, err := coreiface.ParsePath(req.Arguments[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
root := coreiface.ParsePath(req.Arguments[0])
|
||||
|
||||
file, err := cmdenv.GetFileArg(req.Files.Entries())
|
||||
if err != nil {
|
||||
@ -102,10 +99,7 @@ Example:
|
||||
return err
|
||||
}
|
||||
|
||||
root, err := coreiface.ParsePath(req.Arguments[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
root := coreiface.ParsePath(req.Arguments[0])
|
||||
|
||||
file, err := cmdenv.GetFileArg(req.Files.Entries())
|
||||
if err != nil {
|
||||
@ -145,10 +139,7 @@ Remove a Merkle-link from the given object and return the hash of the result.
|
||||
return err
|
||||
}
|
||||
|
||||
root, err := coreiface.ParsePath(req.Arguments[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
root := coreiface.ParsePath(req.Arguments[0])
|
||||
|
||||
name := req.Arguments[1]
|
||||
p, err := api.Object().RmLink(req.Context, root, name)
|
||||
@ -201,17 +192,9 @@ to a file containing 'bar', and returns the hash of the new object.
|
||||
return err
|
||||
}
|
||||
|
||||
root, err := coreiface.ParsePath(req.Arguments[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
root := coreiface.ParsePath(req.Arguments[0])
|
||||
name := req.Arguments[1]
|
||||
|
||||
child, err := coreiface.ParsePath(req.Arguments[2])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
child := coreiface.ParsePath(req.Arguments[2])
|
||||
|
||||
create, _ := req.Options[createOptionName].(bool)
|
||||
if err != nil {
|
||||
|
||||
@ -183,12 +183,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 {
|
||||
p, err := coreiface.ParsePath(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rp, err := api.ResolvePath(ctx, p)
|
||||
rp, err := api.ResolvePath(ctx, coreiface.ParsePath(b))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -238,12 +233,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 {
|
||||
p, err := coreiface.ParsePath(b)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rp, err := api.ResolvePath(req.Context, p)
|
||||
rp, err := api.ResolvePath(req.Context, coreiface.ParsePath(b))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -417,15 +407,8 @@ new pin and removing the old one.
|
||||
|
||||
unpin, _ := req.Options[pinUnpinOptionName].(bool)
|
||||
|
||||
from, err := coreiface.ParsePath(req.Arguments[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
to, err := coreiface.ParsePath(req.Arguments[1])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
from := coreiface.ParsePath(req.Arguments[0])
|
||||
to := coreiface.ParsePath(req.Arguments[1])
|
||||
|
||||
err = api.Pin().Update(req.Context, from, to, options.Pin.Unpin(unpin))
|
||||
if err != nil {
|
||||
@ -514,12 +497,7 @@ func pinLsKeys(ctx context.Context, args []string, typeStr string, n *core.IpfsN
|
||||
keys := make(map[cid.Cid]RefKeyObject)
|
||||
|
||||
for _, p := range args {
|
||||
pth, err := coreiface.ParsePath(p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
c, err := api.ResolvePath(ctx, pth)
|
||||
c, err := api.ResolvePath(ctx, coreiface.ParsePath(p))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -130,12 +130,7 @@ Resolve the value of an IPFS DAG path:
|
||||
}
|
||||
|
||||
// else, ipfs path or ipns with recursive flag
|
||||
p, err := coreiface.ParsePath(name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rp, err := api.ResolvePath(req.Context, p)
|
||||
rp, err := api.ResolvePath(req.Context, coreiface.ParsePath(name))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -96,12 +96,7 @@ possible, please use 'ipfs ls' instead.
|
||||
for _, p := range paths {
|
||||
ctx := req.Context
|
||||
|
||||
fpath, err := iface.ParsePath(p)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
merkleNode, err := api.ResolveNode(ctx, fpath)
|
||||
merkleNode, err := api.ResolveNode(ctx, iface.ParsePath(p))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -28,12 +28,7 @@ func (k *key) Name() string {
|
||||
|
||||
// Path returns the path of the key.
|
||||
func (k *key) Path() coreiface.Path {
|
||||
path, err := coreiface.ParsePath(ipfspath.Join([]string{"/ipns", k.peerID.Pretty()}))
|
||||
if err != nil {
|
||||
panic("error parsing path: " + err.Error())
|
||||
}
|
||||
|
||||
return path
|
||||
return coreiface.ParsePath(ipfspath.Join([]string{"/ipns", k.peerID.Pretty()}))
|
||||
}
|
||||
|
||||
// ID returns key PeerID
|
||||
|
||||
@ -106,10 +106,8 @@ func (api *NameAPI) Search(ctx context.Context, name string, opts ...caopts.Name
|
||||
go func() {
|
||||
defer close(out)
|
||||
for res := range resolver.ResolveAsync(ctx, name, options.ResolveOpts...) {
|
||||
p, _ := coreiface.ParsePath(res.Path.String())
|
||||
|
||||
select {
|
||||
case out <- coreiface.IpnsResult{Path: p, Err: res.Err}:
|
||||
case out <- coreiface.IpnsResult{Path: coreiface.ParsePath(res.Path.String()), Err: res.Err}:
|
||||
case <-ctx.Done():
|
||||
return
|
||||
}
|
||||
|
||||
@ -36,6 +36,9 @@ func (api *CoreAPI) ResolvePath(ctx context.Context, p coreiface.Path) (coreifac
|
||||
if _, ok := p.(coreiface.ResolvedPath); ok {
|
||||
return p.(coreiface.ResolvedPath), nil
|
||||
}
|
||||
if err := p.IsValid(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ipath := ipfspath.Path(p.String())
|
||||
ipath, err := core.ResolveIPNS(ctx, api.namesys, ipath)
|
||||
|
||||
@ -147,8 +147,8 @@ func (i *gatewayHandler) getOrHeadHandler(ctx context.Context, w http.ResponseWr
|
||||
ipnsHostname = true
|
||||
}
|
||||
|
||||
parsedPath, err := coreiface.ParsePath(urlPath)
|
||||
if err != nil {
|
||||
parsedPath := coreiface.ParsePath(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, _ := iface.ParsePath(paths[rand.Intn(len(paths))])
|
||||
item := iface.ParsePath(paths[rand.Intn(len(paths))])
|
||||
|
||||
relpath := strings.Replace(item.String(), item.Namespace(), "", 1)
|
||||
fname := path.Join(mnt.Dir, relpath)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user