Skip to content

Commit 471ad60

Browse files
committed
Add noMove option to migration step in bin.js
1 parent a60a0ae commit 471ad60

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

bin.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
#!/usr/bin/env node
2-
2+
const p = require('path')
3+
const os = require('os')
4+
const fs = require('fs').promises
35
const repl = require('repl')
46
const { Server, Client } = require('./')
57
const minimist = require('minimist')
68
const { migrate: migrateFromDaemon, isMigrated } = require('@hyperspace/migration-tool')
79

10+
// TODO: Default paths are duplicated here because we need to do the async migration check.
11+
const HYPERSPACE_STORAGE_DIR = p.join(os.homedir(), '.hyperspace', 'storage')
12+
const HYPERDRIVE_STORAGE_DIR = p.join(os.homedir(), '.hyperdrive', 'storage', 'cores')
13+
814
const argv = minimist(process.argv.slice(2), {
915
string: ['host', 'storage', 'bootstrap'],
1016
boolean: ['memory-only', 'announce', 'migrate', 'repl'],
@@ -49,17 +55,23 @@ async function main () {
4955
// Note: This will be removed in future releases of Hyperspace.
5056
// If the hyperdrive-daemon -> hyperspace migration has already completed, this is a no-op.
5157
if (argv.migrate) {
52-
if (!(await isMigrated())) {
58+
if (!(await isMigrated({ noMove: true }))) {
5359
console.log('Migrating from Hyperdrive daemon...')
54-
await migrateFromDaemon()
60+
// TODO: For Beaker compat, do not move existing cores into ~/.hyperspace for now.
61+
await migrateFromDaemon({ noMove: true })
5562
console.log('Migration finished.')
5663
}
5764
}
5865

66+
// For now, the storage path is determined as follows:
67+
// If ~/.hyperdrive/storage/cores exists, use that (from an old hyperdrive daemon installation)
68+
// Else, use ~/.hyperspace/storage
69+
const storage = argv.storage ? argv.storage : await getStoragePath()
70+
5971
const s = new Server({
6072
host: argv.host,
6173
port: argv.port,
62-
storage: argv.storage,
74+
storage,
6375
network: argv.bootstrap ? { bootstrap: [].concat(argv.bootstrap) } : null,
6476
memoryOnly: argv['memory-only'],
6577
noAnnounce: !argv.announce,
@@ -121,6 +133,17 @@ async function main () {
121133
}
122134
}
123135

136+
async function getStoragePath () {
137+
try {
138+
// If this dir exists, use it.
139+
await fs.stat(HYPERDRIVE_STORAGE_DIR)
140+
return HYPERDRIVE_STORAGE_DIR
141+
} catch (err) {
142+
if (err.code !== 'ENOENT') throw err
143+
return HYPERSPACE_STORAGE_DIR
144+
}
145+
}
146+
124147
function onerror (err) {
125148
console.error(err.stack)
126149
process.exit(1)

0 commit comments

Comments
 (0)