Skip to content

Commit c387c4f

Browse files
authored
fix: repo fsck is deprecated (#1438)
`ipfs repo fsck` seems to have been deprecated (ipfs/kubo@288a83c) in the meanwhile so our logic wasn't working. I changed it so now we manually check if it's a connection refused error. If so, check if there's a config file. If so, remove the api file. If no config file, then it's a remote api connection, show error to the user. License: MIT Signed-off-by: Henrique Dias <[email protected]>
1 parent 13e265d commit c387c4f

File tree

2 files changed

+13
-27
lines changed

2 files changed

+13
-27
lines changed

src/daemon/config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ function apiFileExists (ipfsd) {
1717
return fs.pathExistsSync(join(ipfsd.path, 'api'))
1818
}
1919

20+
function rmApiFile (ipfsd) {
21+
return fs.removeSync(join(ipfsd.path, 'api'))
22+
}
23+
2024
function configPath (ipfsd) {
2125
return join(ipfsd.path, 'config')
2226
}
@@ -270,6 +274,7 @@ module.exports = Object.freeze({
270274
configPath,
271275
configExists,
272276
apiFileExists,
277+
rmApiFile,
273278
applyDefaults,
274279
checkCorsConfig,
275280
checkPorts

src/daemon/daemon.js

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
const Ctl = require('ipfsd-ctl')
22
const i18n = require('i18next')
3-
const { execFileSync } = require('child_process')
43
const { showDialog } = require('../dialogs')
54
const logger = require('../common/logger')
6-
const { applyDefaults, checkCorsConfig, checkPorts, configExists, apiFileExists } = require('./config')
5+
const { applyDefaults, checkCorsConfig, checkPorts, configExists, rmApiFile, apiFileExists } = require('./config')
76

87
function cannotConnectDialog (addr) {
98
showDialog({
@@ -22,30 +21,6 @@ function getIpfsBinPath () {
2221
.replace('app.asar', 'app.asar.unpacked')
2322
}
2423

25-
async function cleanup (ipfsd) {
26-
const log = logger.start('[daemon] cleanup')
27-
28-
if (!configExists(ipfsd)) {
29-
cannotConnectDialog(ipfsd.apiAddr)
30-
throw new Error('cannot connect to api')
31-
}
32-
33-
log.info('run: ipfs repo fsck')
34-
const exec = getIpfsBinPath()
35-
36-
try {
37-
execFileSync(exec, ['repo', 'fsck'], {
38-
env: {
39-
...process.env,
40-
IPFS_PATH: ipfsd.path
41-
}
42-
})
43-
log.end()
44-
} catch (err) {
45-
log.fail(err)
46-
}
47-
}
48-
4924
async function spawn ({ flags, path, keysize }) {
5025
const ipfsd = await Ctl.createController({
5126
ipfsHttpModule: require('ipfs-http-client'),
@@ -92,7 +67,13 @@ module.exports = async function (opts) {
9267
throw err
9368
}
9469

95-
await cleanup(ipfsd)
70+
if (!configExists(ipfsd)) {
71+
cannotConnectDialog(ipfsd.apiAddr)
72+
throw err
73+
}
74+
75+
logger.info('[daemon] removing api file')
76+
rmApiFile(ipfsd)
9677
await ipfsd.start()
9778
}
9879

0 commit comments

Comments
 (0)