提交 18ebf2e6 作者: Steven Allen

resolve: kill off buggy resolve function

This resolve function assumed that all paths were of the same type (ipfs, ipld,
etc.). The CoreAPI does a much better job.
上级 db98f561
package resolve_test
import (
"testing"
coremock "github.com/ipfs/go-ipfs/core/mock"
"github.com/ipfs/go-ipfs/namesys/resolve"
path "github.com/ipfs/go-path"
)
func TestResolveNoComponents(t *testing.T) {
n, err := coremock.NewMockNode()
if n == nil || err != nil {
t.Fatal("Should have constructed a mock node", err)
}
_, err = resolve.Resolve(n.Context(), n.Namesys, n.Resolver, path.Path("/ipns/"))
if err.Error() != "invalid path \"/ipns/\": ipns path missing IPNS ID" {
t.Error("Should error with no components (/ipns/).", err)
}
_, err = resolve.Resolve(n.Context(), n.Namesys, n.Resolver, path.Path("/ipfs/"))
if err.Error() != "invalid path \"/ipfs/\": not enough path components" {
t.Error("Should error with no components (/ipfs/).", err)
}
_, err = resolve.Resolve(n.Context(), n.Namesys, n.Resolver, path.Path("/../.."))
if err.Error() != "invalid path \"/../..\": unknown namespace \"..\"" {
t.Error("Should error with invalid path.", err)
}
}
......@@ -6,10 +6,8 @@ import (
"fmt"
"strings"
"github.com/ipfs/go-ipld-format"
logging "github.com/ipfs/go-log"
"github.com/ipfs/go-path"
"github.com/ipfs/go-path/resolver"
"github.com/ipfs/go-ipfs/namesys"
)
......@@ -64,16 +62,3 @@ func ResolveIPNS(ctx context.Context, nsys namesys.NameSystem, p path.Path) (pat
}
return p, nil
}
// 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) (format.Node, error) {
p, err := ResolveIPNS(ctx, nsys, p)
if err != nil {
return nil, err
}
// ok, we have an IPFS path now (or what we'll treat as one)
return r.ResolvePath(ctx, p)
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论