mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 10:27:46 +08:00
Move pathresolve
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
This commit is contained in:
parent
d35dac70f0
commit
7046626ecc
@ -9,6 +9,7 @@ import (
|
||||
|
||||
core "github.com/ipfs/go-ipfs/core"
|
||||
cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
|
||||
"github.com/ipfs/go-ipfs/namesys/resolve"
|
||||
|
||||
cid "github.com/ipfs/go-cid"
|
||||
cidenc "github.com/ipfs/go-cidutil/cidenc"
|
||||
@ -173,7 +174,7 @@ func objectsForPaths(ctx context.Context, n *core.IpfsNode, paths []string) ([]i
|
||||
return nil, err
|
||||
}
|
||||
|
||||
o, err := core.Resolve(ctx, n.Namesys, n.Resolver, p)
|
||||
o, err := resolve.Resolve(ctx, n.Namesys, n.Resolver, p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -4,8 +4,8 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/ipfs/go-ipfs/core"
|
||||
"github.com/ipfs/go-ipfs/core/commands/cmdenv"
|
||||
"github.com/ipfs/go-ipfs/namesys/resolve"
|
||||
tar "github.com/ipfs/go-ipfs/tar"
|
||||
|
||||
"github.com/ipfs/go-ipfs-cmdkit"
|
||||
@ -97,7 +97,7 @@ var tarCatCmd = &cmds.Command{
|
||||
return err
|
||||
}
|
||||
|
||||
root, err := core.Resolve(req.Context, nd.Namesys, nd.Resolver, p)
|
||||
root, err := resolve.Resolve(req.Context, nd.Namesys, nd.Resolver, p)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@ import (
|
||||
"fmt"
|
||||
gopath "path"
|
||||
|
||||
"github.com/ipfs/go-ipfs/core"
|
||||
node2 "github.com/ipfs/go-ipfs/namesys/resolve"
|
||||
|
||||
"github.com/ipfs/go-cid"
|
||||
ipld "github.com/ipfs/go-ipld-format"
|
||||
@ -42,8 +42,8 @@ func (api *CoreAPI) ResolvePath(ctx context.Context, p path.Path) (path.Resolved
|
||||
}
|
||||
|
||||
ipath := ipfspath.Path(p.String())
|
||||
ipath, err := core.ResolveIPNS(ctx, api.namesys, ipath)
|
||||
if err == core.ErrNoNamesys {
|
||||
ipath, err := node2.ResolveIPNS(ctx, api.namesys, ipath)
|
||||
if err == node2.ErrNoNamesys {
|
||||
return nil, coreiface.ErrOffline
|
||||
} else if err != nil {
|
||||
return nil, err
|
||||
|
||||
@ -14,6 +14,7 @@ import (
|
||||
|
||||
"github.com/ipfs/go-ipfs/core"
|
||||
"github.com/ipfs/go-ipfs/dagutils"
|
||||
"github.com/ipfs/go-ipfs/namesys/resolve"
|
||||
|
||||
"github.com/dustin/go-humanize"
|
||||
"github.com/ipfs/go-cid"
|
||||
@ -423,7 +424,7 @@ func (i *gatewayHandler) putHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
var newcid cid.Cid
|
||||
rnode, err := core.Resolve(ctx, i.node.Namesys, i.node.Resolver, rootPath)
|
||||
rnode, err := resolve.Resolve(ctx, i.node.Namesys, i.node.Resolver, rootPath)
|
||||
switch ev := err.(type) {
|
||||
case resolver.ErrNoLink:
|
||||
// ev.Node < node where resolve failed
|
||||
|
||||
@ -13,6 +13,8 @@ import (
|
||||
|
||||
core "github.com/ipfs/go-ipfs/core"
|
||||
namesys "github.com/ipfs/go-ipfs/namesys"
|
||||
node2 "github.com/ipfs/go-ipfs/namesys/resolve"
|
||||
|
||||
dag "github.com/ipfs/go-merkledag"
|
||||
path "github.com/ipfs/go-path"
|
||||
ft "github.com/ipfs/go-unixfs"
|
||||
@ -96,7 +98,7 @@ func loadRoot(ctx context.Context, rt *keyRoot, ipfs *core.IpfsNode, name string
|
||||
return nil, err
|
||||
}
|
||||
|
||||
node, err := core.Resolve(ctx, ipfs.Namesys, ipfs.Resolver, p)
|
||||
node, err := node2.Resolve(ctx, ipfs.Namesys, ipfs.Resolver, p)
|
||||
switch err {
|
||||
case nil:
|
||||
case namesys.ErrResolveFailed:
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
package core_test
|
||||
package resolve_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
core "github.com/ipfs/go-ipfs/core"
|
||||
coremock "github.com/ipfs/go-ipfs/core/mock"
|
||||
"github.com/ipfs/go-ipfs/namesys/resolve"
|
||||
|
||||
path "github.com/ipfs/go-path"
|
||||
)
|
||||
|
||||
@ -14,17 +15,17 @@ func TestResolveNoComponents(t *testing.T) {
|
||||
t.Fatal("Should have constructed a mock node", err)
|
||||
}
|
||||
|
||||
_, err = core.Resolve(n.Context(), n.Namesys, n.Resolver, path.Path("/ipns/"))
|
||||
_, err = resolve.Resolve(n.Context(), n.Namesys, n.Resolver, path.Path("/ipns/"))
|
||||
if err != path.ErrNoComponents {
|
||||
t.Fatal("Should error with no components (/ipns/).", err)
|
||||
}
|
||||
|
||||
_, err = core.Resolve(n.Context(), n.Namesys, n.Resolver, path.Path("/ipfs/"))
|
||||
_, err = resolve.Resolve(n.Context(), n.Namesys, n.Resolver, path.Path("/ipfs/"))
|
||||
if err != path.ErrNoComponents {
|
||||
t.Fatal("Should error with no components (/ipfs/).", err)
|
||||
}
|
||||
|
||||
_, err = core.Resolve(n.Context(), n.Namesys, n.Resolver, path.Path("/../.."))
|
||||
_, err = resolve.Resolve(n.Context(), n.Namesys, n.Resolver, path.Path("/../.."))
|
||||
if err != path.ErrBadPath {
|
||||
t.Fatal("Should error with invalid path.", err)
|
||||
}
|
||||
@ -1,18 +1,21 @@
|
||||
package core
|
||||
package resolve
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
namesys "github.com/ipfs/go-ipfs/namesys"
|
||||
|
||||
ipld "github.com/ipfs/go-ipld-format"
|
||||
"github.com/ipfs/go-ipld-format"
|
||||
log2 "github.com/ipfs/go-log"
|
||||
logging "github.com/ipfs/go-log"
|
||||
path "github.com/ipfs/go-path"
|
||||
resolver "github.com/ipfs/go-path/resolver"
|
||||
"github.com/ipfs/go-path"
|
||||
"github.com/ipfs/go-path/resolver"
|
||||
|
||||
"github.com/ipfs/go-ipfs/namesys"
|
||||
)
|
||||
|
||||
var log = logging.Logger("nsresolv")
|
||||
|
||||
// ErrNoNamesys is an explicit error for when an IPFS node doesn't
|
||||
// (yet) have a name system
|
||||
var ErrNoNamesys = errors.New(
|
||||
@ -27,34 +30,34 @@ func ResolveIPNS(ctx context.Context, nsys namesys.NameSystem, p path.Path) (pat
|
||||
|
||||
// TODO(cryptix): we should be able to query the local cache for the path
|
||||
if nsys == nil {
|
||||
evt.Append(logging.LoggableMap{"error": ErrNoNamesys.Error()})
|
||||
evt.Append(log2.LoggableMap{"error": ErrNoNamesys.Error()})
|
||||
return "", ErrNoNamesys
|
||||
}
|
||||
|
||||
seg := p.Segments()
|
||||
|
||||
if len(seg) < 2 || seg[1] == "" { // just "/<protocol/>" without further segments
|
||||
evt.Append(logging.LoggableMap{"error": path.ErrNoComponents.Error()})
|
||||
evt.Append(log2.LoggableMap{"error": path.ErrNoComponents.Error()})
|
||||
return "", path.ErrNoComponents
|
||||
}
|
||||
|
||||
extensions := seg[2:]
|
||||
resolvable, err := path.FromSegments("/", seg[0], seg[1])
|
||||
if err != nil {
|
||||
evt.Append(logging.LoggableMap{"error": err.Error()})
|
||||
evt.Append(log2.LoggableMap{"error": err.Error()})
|
||||
return "", err
|
||||
}
|
||||
|
||||
respath, err := nsys.Resolve(ctx, resolvable.String())
|
||||
if err != nil {
|
||||
evt.Append(logging.LoggableMap{"error": err.Error()})
|
||||
evt.Append(log2.LoggableMap{"error": err.Error()})
|
||||
return "", err
|
||||
}
|
||||
|
||||
segments := append(respath.Segments(), extensions...)
|
||||
p, err = path.FromSegments("/", segments...)
|
||||
if err != nil {
|
||||
evt.Append(logging.LoggableMap{"error": err.Error()})
|
||||
evt.Append(log2.LoggableMap{"error": err.Error()})
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
@ -64,7 +67,7 @@ func ResolveIPNS(ctx context.Context, nsys namesys.NameSystem, p path.Path) (pat
|
||||
// Resolve resolves the given path by parsing out protocol-specific
|
||||
// entries (e.g. /ipns/<node-key>) and then going through the /ipfs/
|
||||
// entries and returning the final node.
|
||||
func Resolve(ctx context.Context, nsys namesys.NameSystem, r *resolver.Resolver, p path.Path) (ipld.Node, error) {
|
||||
func Resolve(ctx context.Context, nsys namesys.NameSystem, r *resolver.Resolver, p path.Path) (format.Node, error) {
|
||||
p, err := ResolveIPNS(ctx, nsys, p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
Loading…
Reference in New Issue
Block a user