@@ -122,7 +122,7 @@ class FuseManager extends EventEmitter {
122
122
} )
123
123
}
124
124
125
- return this . driveManager . get ( key , { ...this . opts , seed : false } )
125
+ return this . driveManager . get ( key , { ...this . opts } )
126
126
. then ( drive => {
127
127
var handlers = this . _handlers . get ( drive )
128
128
if ( ! handlers ) {
@@ -247,30 +247,41 @@ class FuseManager extends EventEmitter {
247
247
}
248
248
249
249
async _driveForPath ( path , opts = { } ) {
250
+ const self = this
250
251
console . error ( 'GETTING DRIVE FOR PATH:' , path )
251
- return new Promise ( async ( resolve , reject ) => {
252
- if ( ! this . _rootDrive ) {
253
- console . log ( 'NO ROOT DRIVE' )
254
- const drive = await this . driveManager . get ( opts . key , { ...opts , seed : false , configure : { rootDrive : true } } )
255
- return resolve ( { drive, root : true } )
256
- }
257
- if ( path . startsWith ( this . _rootMnt ) && path !== this . _rootMnt ) {
258
- const relativePath = path . slice ( this . _rootMnt . length )
259
- if ( ! relativePath . startsWith ( '/home' ) ) throw new Error ( 'You can only mount sub-hyperdrives within the home directory.' )
260
252
261
- console . error ( 'IT IS A SUBDRIVE, RELATIVE:' , relativePath )
262
- return this . _rootDrive . readFile ( p . join ( relativePath , '.key' ) , ( err , key ) => {
253
+ if ( ! this . _rootDrive ) {
254
+ console . log ( 'NO ROOT DRIVE' )
255
+ const drive = await this . driveManager . get ( opts . key , { ...opts , configure : { rootDrive : true } } )
256
+ return { drive, root : true }
257
+ }
258
+
259
+ if ( path . startsWith ( this . _rootMnt ) && path !== this . _rootMnt ) {
260
+ const relativePath = path . slice ( this . _rootMnt . length )
261
+ if ( ! relativePath . startsWith ( '/home' ) ) throw new Error ( 'You can only mount sub-hyperdrives within the home directory.' )
262
+ console . error ( 'IT IS A SUBDRIVE, RELATIVE:' , relativePath )
263
+ return getSubdrive ( relativePath )
264
+ }
265
+
266
+ console . error ( 'path:' , path , 'rootMnt:' , this . _rootMnt , 'claiming it is root' )
267
+ return { drive : this . _rootDrive , root : true }
268
+
269
+ async function getSubdrive ( relativePath ) {
270
+ const key = await new Promise ( ( resolve , reject ) => {
271
+ self . _rootDrive . readFile ( p . join ( relativePath , '.key' ) , ( err , key ) => {
263
272
if ( err && err . errno !== 2 ) return reject ( err )
264
273
key = key ? datEncoding . decode ( key . toString ( 'utf8' ) ) : opts . key
265
- console . error ( 'KEY HERE:' , key , 'OPTS:' , opts )
266
- return this . driveManager . get ( key , { ...opts , seed : ! ! opts . key } )
267
- . then ( drive => resolve ( { drive, root : false , relativePath } ) )
268
- . catch ( reject )
274
+ return resolve ( key )
269
275
} )
276
+ } )
277
+ const drive = await self . driveManager . get ( key , { ...opts } )
278
+ if ( opts . key ) {
279
+ console . error ( 'PUBLISHING DRIVE BY KEY' )
280
+ await self . driveManager . publish ( drive )
281
+ console . error ( 'PUBLISHED' )
270
282
}
271
- console . error ( 'path:' , path , 'rootMnt:' , this . _rootMnt , 'claiming it is root' )
272
- return resolve ( { drive : this . _rootDrive , root : true } )
273
- } )
283
+ return { drive, relativePath, root : false }
284
+ }
274
285
}
275
286
276
287
async mount ( mnt , mountOpts = { } ) {
@@ -284,6 +295,7 @@ class FuseManager extends EventEmitter {
284
295
await this . unmount ( )
285
296
return mountRoot ( drive )
286
297
}
298
+ console . error ( 'MOUNTING SUBDRIVE HERE' )
287
299
return mountSubdrive ( relativePath , drive )
288
300
289
301
async function mountSubdrive ( relativePath , drive ) {
0 commit comments