@@ -16,27 +16,36 @@ module.exports = function (self) {
1616 ipfsPath = normalizePath ( ipfsPath )
1717
1818 const pathComponents = ipfsPath . split ( '/' )
19- const fileNameOrHash = pathComponents [ pathComponents . length - 1 ]
2019 const cid = pathComponents [ 0 ]
21- const filePath = pathComponents . slice ( 1 ) . join ( '/' )
2220
2321 if ( options . preload !== false ) {
2422 self . _preload ( pathComponents [ 0 ] )
2523 }
2624
2725 const d = deferred . source ( )
2826
27+ let closestMatchedLink
28+
2929 pull (
30- exporter ( ipfsPath , self . _ipld , options ) ,
31- pull . filter ( file => file . path === fileNameOrHash ) ,
30+ exporter ( cid , self . _ipld , options ) ,
31+ pull . filter ( link => {
32+ // save the closest matched path so we can show in error if no file was found
33+ if ( ( link . path === ipfsPath . substring ( 0 , link . path . length ) &&
34+ link . depth > closestMatchedLink . depth ) || ! closestMatchedLink ) {
35+ closestMatchedLink = link
36+ }
37+
38+ return link . path === ipfsPath
39+ } ) ,
3240 pull . take ( 1 ) ,
3341 pull . collect ( ( err , files ) => {
3442 if ( err ) {
3543 return d . abort ( err )
3644 }
3745
3846 if ( ! files . length ) {
39- return d . abort ( new Error ( `no file named "${ filePath } " under ${ cid } ` ) )
47+ const fileNotFound = ipfsPath . substring ( closestMatchedLink . path . length + 1 )
48+ return d . abort ( new Error ( `no file named "${ fileNotFound } " under ${ closestMatchedLink . path } ` ) )
4049 }
4150
4251 const file = files [ 0 ]
0 commit comments