@@ -34,17 +34,15 @@ module.exports = (self) => {
34
34
35
35
const path = split . slice ( 3 ) . join ( '/' )
36
36
37
- resolve ( cid , path , ( err , cid ) => {
37
+ resolve ( cid , path , ( err , cid , remainder ) => {
38
38
if ( err ) return cb ( err )
39
- if ( ! cid ) return cb ( new Error ( 'found non-link at given path' ) )
40
- cb ( null , `/ipfs/${ cidToString ( cid , { base : opts . cidBase } ) } ` )
39
+ cb ( null , `/ipfs/${ cidToString ( cid , { base : opts . cidBase } ) } ${ ! remainder ? '/' + remainder : '' } ` )
41
40
} )
42
41
} )
43
42
44
43
// Resolve the given CID + path to a CID.
45
44
function resolve ( cid , path , callback ) {
46
45
let value
47
-
48
46
doUntil (
49
47
( cb ) => {
50
48
self . block . get ( cid , ( err , block ) => {
@@ -65,22 +63,20 @@ module.exports = (self) => {
65
63
} )
66
64
} ,
67
65
( ) => {
68
- const endReached = ! path || path === '/'
69
-
70
- if ( endReached ) {
71
- return true
72
- }
73
-
74
- if ( value ) {
66
+ if ( value && value [ '/' ] ) {
67
+ // If we've hit a CID, replace the current CID.
75
68
cid = new CID ( value [ '/' ] )
69
+ } else {
70
+ // We've hit a value. Return the current CID and the remaining path.
71
+ return false
76
72
}
77
73
78
- return false
74
+ // Continue resolving unless the path is empty.
75
+ return ! path || path === '/'
79
76
} ,
80
77
( err ) => {
81
78
if ( err ) return callback ( err )
82
- if ( value && value [ '/' ] ) return callback ( null , new CID ( value [ '/' ] ) )
83
- callback ( )
79
+ callback ( null , cid , path )
84
80
}
85
81
)
86
82
}
0 commit comments