mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-25 12:27:43 +08:00
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.
This commit is contained in:
parent
8643d949f3
commit
97bc89d560
@ -1,32 +0,0 @@
|
||||
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,9 +6,7 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/ipfs/go-ipld-format"
|
||||
"github.com/ipfs/go-path"
|
||||
"github.com/ipfs/go-path/resolver"
|
||||
|
||||
"github.com/ipfs/go-ipfs/namesys"
|
||||
)
|
||||
@ -52,16 +50,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)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user