diff --git a/src/daemon/config.js b/src/daemon/config.js index a3d329e28..af400a38b 100644 --- a/src/daemon/config.js +++ b/src/daemon/config.js @@ -17,6 +17,10 @@ function apiFileExists (ipfsd) { return fs.pathExistsSync(join(ipfsd.path, 'api')) } +function rmApiFile (ipfsd) { + return fs.removeSync(join(ipfsd.path, 'api')) +} + function configPath (ipfsd) { return join(ipfsd.path, 'config') } @@ -270,6 +274,7 @@ module.exports = Object.freeze({ configPath, configExists, apiFileExists, + rmApiFile, applyDefaults, checkCorsConfig, checkPorts diff --git a/src/daemon/daemon.js b/src/daemon/daemon.js index f26209391..b8ad10d0b 100644 --- a/src/daemon/daemon.js +++ b/src/daemon/daemon.js @@ -1,9 +1,8 @@ const Ctl = require('ipfsd-ctl') const i18n = require('i18next') -const { execFileSync } = require('child_process') const { showDialog } = require('../dialogs') const logger = require('../common/logger') -const { applyDefaults, checkCorsConfig, checkPorts, configExists, apiFileExists } = require('./config') +const { applyDefaults, checkCorsConfig, checkPorts, configExists, rmApiFile, apiFileExists } = require('./config') function cannotConnectDialog (addr) { showDialog({ @@ -22,30 +21,6 @@ function getIpfsBinPath () { .replace('app.asar', 'app.asar.unpacked') } -async function cleanup (ipfsd) { - const log = logger.start('[daemon] cleanup') - - if (!configExists(ipfsd)) { - cannotConnectDialog(ipfsd.apiAddr) - throw new Error('cannot connect to api') - } - - log.info('run: ipfs repo fsck') - const exec = getIpfsBinPath() - - try { - execFileSync(exec, ['repo', 'fsck'], { - env: { - ...process.env, - IPFS_PATH: ipfsd.path - } - }) - log.end() - } catch (err) { - log.fail(err) - } -} - async function spawn ({ flags, path, keysize }) { const ipfsd = await Ctl.createController({ ipfsHttpModule: require('ipfs-http-client'), @@ -92,7 +67,13 @@ module.exports = async function (opts) { throw err } - await cleanup(ipfsd) + if (!configExists(ipfsd)) { + cannotConnectDialog(ipfsd.apiAddr) + throw err + } + + logger.info('[daemon] removing api file') + rmApiFile(ipfsd) await ipfsd.start() }