Skip to content

Commit

Permalink
fix: repo fsck is deprecated
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>
  • Loading branch information
hacdias committed Apr 24, 2020
1 parent dfad823 commit b80892d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 27 deletions.
5 changes: 5 additions & 0 deletions src/daemon/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
Expand Down Expand Up @@ -270,6 +274,7 @@ module.exports = Object.freeze({
configPath,
configExists,
apiFileExists,
rmApiFile,
applyDefaults,
checkCorsConfig,
checkPorts
Expand Down
35 changes: 8 additions & 27 deletions src/daemon/daemon.js
Original file line number Diff line number Diff line change
@@ -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({
Expand All @@ -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'),
Expand Down Expand Up @@ -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()
}

Expand Down

0 comments on commit b80892d

Please sign in to comment.