Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: repo fsck is deprecated #1438

Merged
merged 1 commit into from
Apr 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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