From a7e15ffd27cdb8497dc9a881103113ce7a1938fd Mon Sep 17 00:00:00 2001 From: Michael FIG Date: Mon, 22 Feb 2021 18:42:40 -0600 Subject: [PATCH] fix: make init-basedir more tolerant to paths --- .../cosmic-swingset/lib/ag-solo/init-basedir.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/packages/cosmic-swingset/lib/ag-solo/init-basedir.js b/packages/cosmic-swingset/lib/ag-solo/init-basedir.js index 6a1744551ff..530fdabb507 100644 --- a/packages/cosmic-swingset/lib/ag-solo/init-basedir.js +++ b/packages/cosmic-swingset/lib/ag-solo/init-basedir.js @@ -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'); @@ -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'),