Skip to content

Commit

Permalink
fix: make init-basedir more tolerant to paths
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Feb 23, 2021
1 parent 6959647 commit a7e15ff
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions packages/cosmic-swingset/lib/ag-solo/init-basedir.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import fs from 'fs';
import path from 'path';
import { execFileSync } from 'child_process';

import { assert, details as X } from '@agoric/assert';
import anylogger from 'anylogger';

const log = anylogger('ag-solo:init');
Expand All @@ -20,17 +21,15 @@ export default function initBasedir(
options.wallet = wallet;

const here = __dirname;
try {
fs.mkdirSync(basedir, 0o700);
} catch (e) {
if (!fs.existsSync(path.join(basedir, 'ag-cosmos-helper-address'))) {
log.error(
`unable to create basedir ${basedir}, it must not already exist`,
);
throw e;
}
if (
fs.existsSync(basedir) &&
!fs.existsSync(path.join(basedir, 'ag-cosmos-helper-address'))
) {
assert.fail(X`${basedir} must not already exist`);
}

fs.mkdirSync(basedir, { mode: 0o700, recursive: true });

const connections = [{ type: 'http', port: webport, host: webhost }];
fs.writeFileSync(
path.join(basedir, 'connections.json'),
Expand Down

0 comments on commit a7e15ff

Please sign in to comment.