Skip to content

Commit eae1cb5

Browse files
committed
Use seedIndex instead of driveIndex for seeding
1 parent 7f488b0 commit eae1cb5

File tree

2 files changed

+36
-24
lines changed

2 files changed

+36
-24
lines changed

lib/drives/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class DriveManager extends EventEmitter {
3737
}
3838

3939
async _reseed () {
40-
const driveList = await collect(this._driveIndex)
40+
const driveList = await collect(this._seedIndex)
4141
for (const { key: discoveryKey } of driveList) {
4242
this.networking.seed(discoveryKey)
4343
}
@@ -158,16 +158,16 @@ class DriveManager extends EventEmitter {
158158
return drive
159159
}
160160

161-
async publish (drive) {
161+
publish (drive) {
162162
const encodedKey = datEncoding.encode(drive.discoveryKey)
163163
this.networking.seed(drive.discoveryKey)
164-
await this._seedIndex.put(encodedKey, '')
164+
return this._seedIndex.put(encodedKey, '')
165165
}
166166

167-
async unpublish (drive) {
167+
unpublish (drive) {
168168
const encodedKey = datEncoding.encode(drive.discoveryKey)
169169
this.networking.unseed(drive.discoveryKey)
170-
await this._seedIndex.del(encodedKey)
170+
return this._seedIndex.del(encodedKey)
171171
}
172172

173173
// TODO: Retrieving stats from managed hyperdrives is trickier with corestores/mounts.

lib/fuse/index.js

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class FuseManager extends EventEmitter {
122122
})
123123
}
124124

125-
return this.driveManager.get(key, { ...this.opts, seed: false })
125+
return this.driveManager.get(key, { ...this.opts })
126126
.then(drive => {
127127
var handlers = this._handlers.get(drive)
128128
if (!handlers) {
@@ -247,30 +247,41 @@ class FuseManager extends EventEmitter {
247247
}
248248

249249
async _driveForPath (path, opts = {}) {
250+
const self = this
250251
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.')
260252

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) => {
263272
if (err && err.errno !== 2) return reject(err)
264273
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)
269275
})
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')
270282
}
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+
}
274285
}
275286

276287
async mount (mnt, mountOpts = {}) {
@@ -284,6 +295,7 @@ class FuseManager extends EventEmitter {
284295
await this.unmount()
285296
return mountRoot(drive)
286297
}
298+
console.error('MOUNTING SUBDRIVE HERE')
287299
return mountSubdrive(relativePath, drive)
288300

289301
async function mountSubdrive (relativePath, drive) {

0 commit comments

Comments
 (0)