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: cleanup repository before starting up IPFS #722

Merged
merged 21 commits into from
Dec 8, 2018
Merged
Changes from 2 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
53 changes: 53 additions & 0 deletions src/utils/daemon.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,56 @@
import IPFSFactory from 'ipfsd-ctl'
import logger from './logger'
import fs from 'fs-extra'
import { join } from 'path'
import { dialog, app } from 'electron'

async function cleanup (path) {
logger.info('Cleaning up repository %s', path)

const lockFile = join(path, 'repo.lock')
const apiFile = join(path, 'api')
const cfgFile = join(path, 'config')

if (await fs.pathExists(lockFile)) {
return
}

if (!await fs.pathExists(apiFile)) {
return
}

const cfg = await fs.readJSON(cfgFile)
const cfgAddr = cfg.Addresses ? cfg.Addresses.API : ''
const addr = (await fs.readFile(apiFile)).toString()
hacdias marked this conversation as resolved.
Show resolved Hide resolved
let clean = cfgAddr === addr

if (!clean && addr) {
const option = dialog.showMessageBox({
type: 'warning',
title: 'IPFS Desktop',
message: `We noticed your configured API address doesn't match the API address on your api file (${apiFile}). Do you wish to continue?`,
buttons: [
'No',
'Yes',
'Yes, but remove the api file'
],
cancelId: 0
})

if (option === 0) {
app.exit(1)
} else if (option === 1) {
clean = false
} else {
clean = true
}
}

if (clean) {
logger.info('Removing api file: %s', apiFile)
return fs.remove(apiFile)
}
}

export default async function createDaemon (opts) {
opts.type = opts.type || 'go'
Expand Down Expand Up @@ -34,6 +85,8 @@ export default async function createDaemon (opts) {
})
})

await cleanup(ipfsd.repoPath)

if (!ipfsd.started) {
await new Promise((resolve, reject) => {
ipfsd.start(opts.flags, err => {
Expand Down