Skip to content

Commit afcbe03

Browse files
committed
Remove unused file + standardize + remove ora dep
1 parent f22a16a commit afcbe03

File tree

13 files changed

+27
-327
lines changed

13 files changed

+27
-327
lines changed

bin/setup.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
const p = require('path')
22
const fs = require('fs')
3-
const { spawn, exec } = require('child_process')
3+
const { exec } = require('child_process')
44

55
try {
66
var hyperfuse = require('hyperdrive-fuse')
77
} catch (err) {
88
console.warn('FUSE installation failed. You will be unable to mount your hyperdrives.')
99
}
1010

11-
const ora = require('ora')
1211
const chalk = require('chalk')
1312

1413
exports.command = 'setup'

bin/start.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const p = require('path')
2-
const os = require('os')
32

43
const chalk = require('chalk')
54
const forever = require('forever')
@@ -19,7 +18,7 @@ exports.builder = {
1918
storage: {
2019
description: 'The storage directory for hyperdrives and associated metadata.',
2120
type: 'string',
22-
default: constants.storage,
21+
default: constants.storage
2322
},
2423
'log-level': {
2524
description: 'The log level',

cli.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,3 @@ client.commandDir('bin')
55
.demandCommand()
66
.help()
77
.argv
8-
9-
10-

index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const p = require('path')
2-
const os = require('os')
31
const { EventEmitter } = require('events')
42

53
const mkdirp = require('mkdirp')
@@ -10,12 +8,11 @@ const grpc = require('@grpc/grpc-js')
108
const corestore = require('corestore')
119
const SwarmNetworker = require('corestore-swarm-networking')
1210

13-
1411
const { rpc, loadMetadata } = require('hyperdrive-daemon-client')
1512
const constants = require('hyperdrive-daemon-client/lib/constants')
1613

1714
const DriveManager = require('./lib/drives')
18-
const { catchErrors, serverError, requestError } = require('./lib/errors')
15+
const { serverError } = require('./lib/errors')
1916

2017
try {
2118
var hyperfuse = require('hyperdrive-fuse')
@@ -143,6 +140,7 @@ class HyperdriveDaemon extends EventEmitter {
143140

144141
async stop () {
145142
if (this._isClosed) return Promise.resolve()
143+
if (this.server) this.server.forceShutdown()
146144

147145
if (this.fuse && this.fuse.fuseConfigured) await this.fuse.unmount()
148146
if (this.networking) await this.networking.close()

lib/drives/index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const crypto = require('crypto')
21
const { EventEmitter } = require('events')
32

43
const hyperdrive = require('hyperdrive')
@@ -14,7 +13,6 @@ const {
1413
toHyperdriveOptions,
1514
fromStat,
1615
toStat,
17-
toMount,
1816
fromMount,
1917
toDriveStats,
2018
toChunks
@@ -135,7 +133,7 @@ class DriveManager extends EventEmitter {
135133

136134
async getAllStats () {
137135
const allStats = []
138-
for (const [keyString, drive] of this._drives) {
136+
for (const [, drive] of this._drives) {
139137
const driveStats = await this.getDriveStats(drive)
140138
allStats.push(driveStats)
141139
}
@@ -574,7 +572,7 @@ class DriveManager extends EventEmitter {
574572
close: async (call) => {
575573
const id = call.request.getId()
576574

577-
const drive = this.driveForSession(id)
575+
this.driveForSession(id)
578576
this.closeSession(id)
579577
const rsp = new rpc.drive.messages.CloseSessionResponse()
580578

lib/fuse/index.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ const p = require('path')
22
const { EventEmitter } = require('events')
33
const crypto = require('crypto')
44

5-
const hyperdrive = require('hyperdrive')
65
const datEncoding = require('dat-encoding')
76
const Stat = require('hyperdrive/lib/stat')
87
const hyperfuse = require('hyperdrive-fuse')
98

10-
119
const { rpc } = require('hyperdrive-daemon-client')
1210
const { fromHyperdriveOptions, toHyperdriveOptions } = require('hyperdrive-daemon-client/lib/common')
1311
const constants = require('hyperdrive-daemon-client/lib/constants')
@@ -59,7 +57,6 @@ class FuseManager extends EventEmitter {
5957
}
6058

6159
_wrapHandlers (handlers) {
62-
const self = this
6360
const interceptorIndex = new Map()
6461

6562
const RootListHandler = {
@@ -96,7 +93,7 @@ class FuseManager extends EventEmitter {
9693
if (!match.groups['key']) {
9794
if (op === 'readdir') return cb(0, [])
9895
if (op === 'releasedir') return cb(0)
99-
if (op === 'getattr') return cb(0, Stat.directory({ uid: process.getuid(), gid: process.getgid()}))
96+
if (op === 'getattr') return cb(0, Stat.directory({ uid: process.getuid(), gid: process.getgid() }))
10097
return handlers[op].apply(null, [...args, cb])
10198
}
10299

@@ -204,7 +201,7 @@ class FuseManager extends EventEmitter {
204201

205202
function wrapHandler (handlerName, handler) {
206203
log.debug({ handlerName }, 'wrapping handler')
207-
const activeInterceptors = interceptors.filter(({ ops }) => ops === '*' || (ops.indexOf(handlerName) !== -1))
204+
const activeInterceptors = interceptors.filter(({ ops }) => ops === '*' || (ops.indexOf(handlerName) !== -1))
208205
if (!activeInterceptors.length) return handler
209206

210207
const matcher = new RegExp(activeInterceptors.map(({ test, id }) => `(?<${id}>${test})`).join('|'))
@@ -239,7 +236,7 @@ class FuseManager extends EventEmitter {
239236
if (!this._rootDrive && path !== constants.mountpoint) {
240237
throw new Error(`You can only mount the root drive at ${constants.mountpoint}`)
241238
}
242-
if (!this._rootDrive) return { path: constants.mountpoint, root: true}
239+
if (!this._rootDrive) return { path: constants.mountpoint, root: true }
243240
if (path.startsWith(this._rootMnt) && path !== this._rootMnt) {
244241
const relativePath = path.slice(this._rootMnt.length)
245242
if (!relativePath.startsWith('/home')) throw new Error('You can only mount sub-hyperdrives within the home directory.')
@@ -309,13 +306,13 @@ class FuseManager extends EventEmitter {
309306
}
310307

311308
async function mountRoot (drive) {
312-
log.debug({ key: drive.key.toString('hex')}, 'mounting the root drive')
309+
log.debug({ key: drive.key.toString('hex') }, 'mounting the root drive')
313310
const fuseLogger = log.child({ component: 'fuse' })
314311

315312
const handlers = hyperfuse.getHandlers(drive, mnt)
316313
const wrappedHandlers = self._wrapHandlers(handlers)
317314

318-
var mountInfo = await hyperfuse.mount(drive, wrappedHandlers, mnt, {
315+
await hyperfuse.mount(drive, wrappedHandlers, mnt, {
319316
force: true,
320317
displayFolder: true,
321318
log: fuseLogger.trace.bind(fuseLogger),

lib/log.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
const os = require('os')
2-
const p = require('path')
3-
41
const pino = require('pino')
52
const argv = require('yargs').argv
63
const constants = require('hyperdrive-daemon-client/lib/constants')
@@ -9,5 +6,5 @@ const constants = require('hyperdrive-daemon-client/lib/constants')
96
module.exports = pino({
107
name: 'hyperdrive',
118
level: argv['log-level'] || 'info',
12-
enabled: true,
9+
enabled: true
1310
}, (process.env['NODE_ENV'] === 'test') ? pino.destination(2) : constants.structuredLog)

lib/metadata.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const p = require('path')
2-
const os = require('os')
31
const fs = require('fs-extra')
42

53
const sodium = require('sodium-universal')

0 commit comments

Comments
 (0)