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

feat: show repo migration (go-ipfs 0.12.0) #1982

Merged
merged 9 commits into from
Mar 1, 2022
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
9 changes: 9 additions & 0 deletions assets/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -225,5 +225,14 @@
"message": "Ongoing operation is taking more resources than expected. Do you wish to abort, and forcefully reload the interface?",
"forceReload": "Yes, reload",
"doNothing": "Do nothing"
},
"migrationDialog": {
"title": "IPFS Desktop Migration",
"message": "One moment! IPFS Desktop needs to run the latest data store migrations:",
"closeAndContinue": "Continue in the background"
},
"migrationFailedDialog": {
"title": "IPFS Desktop Migration Has Failed",
"message": "IPFS has encountered an error and migration could not be completed:"
}
}
29 changes: 7 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"electron-updater": "4.6.1",
"fix-path": "3.0.0",
"fs-extra": "^10.0.0",
"go-ipfs": "0.11.0",
"go-ipfs": "0.12.0",
"i18next": "^21.6.10",
"i18next-electron-language-detector": "0.0.10",
"i18next-fs-backend": "1.1.4",
Expand Down
108 changes: 95 additions & 13 deletions src/daemon/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ const Ctl = require('ipfsd-ctl')
const i18n = require('i18next')
const { showDialog } = require('../dialogs')
const logger = require('../common/logger')
const { applyDefaults, migrateConfig, checkCorsConfig, checkPorts, configExists, rmApiFile, apiFileExists } = require('./config')
const { getCustomBinary } = require('../custom-ipfs-binary')
const { applyDefaults, migrateConfig, checkCorsConfig, checkPorts, configExists, rmApiFile, apiFileExists } = require('./config')
const showMigrationPrompt = require('./migration-prompt')

function cannotConnectDialog (addr) {
showDialog({
Expand Down Expand Up @@ -57,29 +58,110 @@ async function spawn ({ flags, path }) {
return { ipfsd, isRemote: false }
}

module.exports = async function (opts) {
const { ipfsd, isRemote } = await spawn(opts)
if (!isRemote) await checkPorts(ipfsd)
function listenToIpfsLogs (ipfsd, callback) {
let stdout, stderr

const listener = data => {
callback(data.toString())
}

const interval = setInterval(() => {
if (!ipfsd.subprocess) {
return
}

stdout = ipfsd.subprocess.stdout
stderr = ipfsd.subprocess.stderr

stdout.on('data', listener)
stderr.on('data', listener)

clearInterval(interval)
}, 20)

const stop = () => {
clearInterval(interval)

if (stdout) stdout.removeListener('data', listener)
if (stderr) stderr.removeListener('data', listener)
}

return stop
}

async function startIpfsWithLogs (ipfsd) {
let err, id, migrationPrompt
let isMigrating, isErrored, isFinished
let logs = ''

const stopListening = listenToIpfsLogs(ipfsd, data => {
logs += data.toString()

isMigrating = isMigrating || logs.toLowerCase().includes('migration')
isErrored = isErrored || logs.toLowerCase().includes('error')
isFinished = isFinished || logs.toLowerCase().includes('daemon is ready')

if (!isMigrating) {
return
}

if (!migrationPrompt) {
logger.info('[daemon] ipfs data store is migrating')
migrationPrompt = showMigrationPrompt(logs, isErrored, isFinished)
return
}

if (isErrored || isFinished) {
// forced show on error or when finished,
// because user could close it to run in background
migrationPrompt.loadWindow(logs, isErrored, isFinished)
} else { // update progress if the window is still around
migrationPrompt.update(logs)
}
})

try {
await ipfsd.start()
const { id } = await ipfsd.api.id()
logger.info(`[daemon] PeerID is ${id}`)
logger.info(`[daemon] Repo is at ${ipfsd.path}`)
} catch (err) {
if (!err.message.includes('ECONNREFUSED') && !err.message.includes('ERR_CONNECTION_REFUSED')) {
throw err
const idRes = await ipfsd.api.id()
id = idRes.id
} catch (e) {
err = e
} finally {
// stop monitoring daemon output - we only care about migration phase
stopListening()
if (isErrored) { // save daemon output to error.log
logger.error(logs)
}
}

return {
err, id, logs
}
}

module.exports = async function (opts) {
const { ipfsd, isRemote } = await spawn(opts)
if (!isRemote) {
await checkPorts(ipfsd)
}

let errLogs = await startIpfsWithLogs(ipfsd)

if (errLogs.err) {
if (!errLogs.err.message.includes('ECONNREFUSED') && !errLogs.err.message.includes('ERR_CONNECTION_REFUSED')) {
return { ipfsd, err: errLogs.err, logs: errLogs.logs }
}

if (!configExists(ipfsd)) {
cannotConnectDialog(ipfsd.apiAddr.toString())
throw err
return { ipfsd, err: errLogs.err, logs: errLogs.logs }
}

logger.info('[daemon] removing api file')
rmApiFile(ipfsd)
await ipfsd.start()

errLogs = await startIpfsWithLogs(ipfsd)
}

return ipfsd
return { ipfsd, err: errLogs.err, logs: errLogs.logs, id: errLogs.id }
}
35 changes: 20 additions & 15 deletions src/daemon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,29 @@ module.exports = async function (ctx) {
const config = store.get('ipfsConfig')
updateStatus(STATUS.STARTING_STARTED)

try {
ipfsd = await createDaemon(config)
const { id } = await ipfsd.api.id()

// Update the path if it was blank previously.
// This way we use the default path when it is
// not set.
if (!config.path || typeof config.path !== 'string') {
config.path = ipfsd.path
store.set('ipfsConfig', config)
}
const res = await createDaemon(config)

log.end()
updateStatus(STATUS.STARTING_FINISHED, id)
} catch (err) {
log.fail(err)
if (res.err) {
log.fail(res.err)
updateStatus(STATUS.STARTING_FAILED)
return
}

ipfsd = res.ipfsd

logger.info(`[daemon] PeerID is ${res.id}`)
logger.info(`[daemon] Repo is at ${ipfsd.path}`)

// Update the path if it was blank previously.
// This way we use the default path when it is
// not set.
if (!config.path || typeof config.path !== 'string') {
config.path = ipfsd.path
store.set('ipfsConfig', config)
}

log.end()
updateStatus(STATUS.STARTING_FINISHED, res.id)
}

const stopIpfs = async () => {
Expand Down
Loading