@@ -22,7 +22,7 @@ func (api *CoreAPI) ResolveNode(ctx context.Context, p path.Path) (ipld.Node, er
22
22
ctx , span := tracing .Span (ctx , "CoreAPI" , "ResolveNode" , trace .WithAttributes (attribute .String ("path" , p .String ())))
23
23
defer span .End ()
24
24
25
- rp , err := api .ResolvePath (ctx , p )
25
+ rp , _ , err := api .ResolvePath (ctx , p )
26
26
if err != nil {
27
27
return nil , err
28
28
}
@@ -36,40 +36,49 @@ func (api *CoreAPI) ResolveNode(ctx context.Context, p path.Path) (ipld.Node, er
36
36
37
37
// ResolvePath resolves the path `p` using Unixfs resolver, returns the
38
38
// resolved path.
39
- func (api * CoreAPI ) ResolvePath (ctx context.Context , p path.Path ) (path.ImmutablePath , error ) {
39
+ func (api * CoreAPI ) ResolvePath (ctx context.Context , p path.Path ) (path.ImmutablePath , [] string , error ) {
40
40
ctx , span := tracing .Span (ctx , "CoreAPI" , "ResolvePath" , trace .WithAttributes (attribute .String ("path" , p .String ())))
41
41
defer span .End ()
42
42
43
43
p , err := resolve .ResolveIPNS (ctx , api .namesys , p )
44
44
if err == resolve .ErrNoNamesys {
45
- return nil , coreiface .ErrOffline
45
+ return nil , nil , coreiface .ErrOffline
46
46
} else if err != nil {
47
- return nil , err
48
- }
49
-
50
- if p .Namespace () != path .IPFSNamespace && p .Namespace () != path .IPLDNamespace {
51
- return nil , fmt .Errorf ("unsupported path namespace: %s" , p .Namespace ().String ())
47
+ return nil , nil , err
52
48
}
53
49
54
50
var resolver ipfspathresolver.Resolver
55
- if p .Namespace () == path .IPLDNamespace {
51
+ switch p .Namespace () {
52
+ case path .IPLDNamespace :
56
53
resolver = api .ipldPathResolver
57
- } else {
54
+ case path . IPFSNamespace :
58
55
resolver = api .unixFSPathResolver
56
+ default :
57
+ return nil , nil , fmt .Errorf ("unsupported path namespace: %s" , p .Namespace ().String ())
59
58
}
60
59
61
- node , rest , err := resolver . ResolveToLastNode ( ctx , p )
60
+ imPath , err := path . NewImmutablePath ( p )
62
61
if err != nil {
63
- return nil , err
62
+ return nil , nil , err
63
+ }
64
+
65
+ node , remainder , err := resolver .ResolveToLastNode (ctx , imPath )
66
+ if err != nil {
67
+ return nil , nil , err
64
68
}
65
69
66
70
segments := []string {p .Namespace ().String (), node .String ()}
67
- segments = append (segments , rest ... )
71
+ segments = append (segments , remainder ... )
68
72
69
73
p , err = path .NewPathFromSegments (segments ... )
70
74
if err != nil {
71
- return nil , err
75
+ return nil , nil , err
76
+ }
77
+
78
+ imPath , err = path .NewImmutablePath (p )
79
+ if err != nil {
80
+ return nil , nil , err
72
81
}
73
82
74
- return path . NewImmutablePath ( p )
83
+ return imPath , remainder , nil
75
84
}
0 commit comments