Skip to content

Commit 7f8f4c8

Browse files
committed
Added _getMountPath
1 parent c59441a commit 7f8f4c8

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

lib/drives/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ class DriveManager extends EventEmitter {
112112
newDrive = true
113113
}
114114

115+
console.error('GETTING CORESTORE WITH OPTS:', { ...this.opts, ...opts })
115116
const corestore = this.megastore.get(name, { ...this.opts, ...opts })
116117
const driveOpts = {
117118
...opts,

lib/fuse/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,24 +236,39 @@ class FuseManager extends EventEmitter {
236236
}
237237
}
238238

239+
_getMountPath (path) {
240+
if (!this._rootDrive && path !== '/hyperdrive') throw new Error('You can only mount the root drive at /hyperdrive')
241+
if (!this._rootDrive) return { path: '/hyperdrive', root: true}
242+
if (path.startsWith(this._rootMnt) && path !== this._rootMnt) {
243+
const relativePath = path.slice(this._rootMnt.length)
244+
if (!relativePath.startsWith('/home')) throw new Error('You can only mount sub-hyperdrives within the home directory.')
245+
return { path: relativePath, root: false }
246+
}
247+
}
248+
239249
async _driveForPath (path, opts = {}) {
250+
console.error('GETTING DRIVE FOR PATH:', path)
240251
return new Promise(async (resolve, reject) => {
241252
if (!this._rootDrive) {
253+
console.log('NO ROOT DRIVE')
242254
const drive = await this.driveManager.get(opts.key, { ...opts, seed: false, configure: { rootDrive: true } })
243255
return resolve({ drive, root: true })
244256
}
245257
if (path.startsWith(this._rootMnt) && path !== this._rootMnt) {
246258
const relativePath = path.slice(this._rootMnt.length)
247259
if (!relativePath.startsWith('/home')) throw new Error('You can only mount sub-hyperdrives within the home directory.')
248260

261+
console.error('IT IS A SUBDRIVE, RELATIVE:', relativePath)
249262
return this._rootDrive.readFile(p.join(relativePath, '.key'), (err, key) => {
250263
if (err && err.errno !== 2) return reject(err)
251264
key = key ? datEncoding.decode(key.toString('utf8')) : opts.key
265+
console.error('KEY HERE:', key, 'OPTS:', opts)
252266
return this.driveManager.get(key, { ...opts, seed: !!opts.key })
253267
.then(drive => resolve({ drive, root: false, relativePath }))
254268
.catch(reject)
255269
})
256270
}
271+
console.error('path:', path, 'rootMnt:', this._rootMnt, 'claiming it is root')
257272
return resolve({ drive: this._rootDrive, root: true })
258273
})
259274
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"hyperdrive-fuse": "^1.1.0",
3939
"level": "^4.0.0",
4040
"mkdirp": "^0.5.1",
41-
"megastore": "^0.9.8",
41+
"mini-megastore": "^1.0.0",
4242
"megastore-swarm-networking": "^1.0.0",
4343
"ora": "^3.4.0",
4444
"pino": "^5.12.6",

0 commit comments

Comments
 (0)