From 6a24cf9c8e2075d66803107bed1f4c19d644266e Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Sat, 24 Nov 2018 10:33:16 +0000 Subject: [PATCH 1/2] feat: do not cleanup api/repo.lock License: MIT Signed-off-by: Henrique Dias --- src/utils/daemon.js | 34 ---------------------------------- 1 file changed, 34 deletions(-) diff --git a/src/utils/daemon.js b/src/utils/daemon.js index 01ac4198b..159443731 100644 --- a/src/utils/daemon.js +++ b/src/utils/daemon.js @@ -1,7 +1,5 @@ import IPFSFactory from 'ipfsd-ctl' -import { join } from 'path' import fs from 'fs-extra' -import logger from './logger' export default async function createDaemon (opts) { opts.type = opts.type || 'go' @@ -14,17 +12,10 @@ export default async function createDaemon (opts) { } const init = !(await fs.pathExists(opts.path)) || fs.readdirSync(opts.path).length === 0 - - if (!init) { - await cleanLocks(opts.path) - } - const factory = IPFSFactory.create({ type: opts.type }) const ipfsd = await new Promise((resolve, reject) => { factory.spawn({ - init: false, - start: false, disposable: false, defaultAddrs: true, repoPath: opts.path @@ -65,28 +56,3 @@ export default async function createDaemon (opts) { return ipfsd } - -function cleanLocks (path) { - // This fixes a bug on Windows, where the daemon seems - // not to be exiting correctly, hence the file is not - // removed. - logger.info('Cleaning repo.lock and api files') - const lockPath = join(path, 'repo.lock') - const apiPath = join(path, 'api') - - if (fs.existsSync(lockPath)) { - try { - fs.unlinkSync(lockPath) - } catch (_) { - logger.warn('Could not remove repo.lock. Daemon might be running') - } - } - - if (fs.existsSync(apiPath)) { - try { - fs.unlinkSync(apiPath) - } catch (_) { - logger.warn('Could not remove api. Daemon might be running') - } - } -} From 9f4adee1c4d30bd4f4754a71903417f0c738beec Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Sat, 24 Nov 2018 10:54:41 +0000 Subject: [PATCH 2/2] feat: use default path provided by ipfsd-ctl License: MIT Signed-off-by: Henrique Dias --- src/index.js | 16 +++++++++++----- src/utils/daemon.js | 4 +--- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/index.js b/src/index.js index 7afc3166e..2e1be5814 100644 --- a/src/index.js +++ b/src/index.js @@ -55,17 +55,23 @@ function handleError (e) { async function setupConnection () { let config = store.get('config') + let updateCfg = false if (config === null) { - config = { - type: 'go', - path: join(app.getPath('home'), '.ipfs') - } + config = { type: 'go' } + updateCfg = true + } + + const ipfsd = await createDaemon(config) + // createDaemon has changed the config object, + // but didn't add the repo variable. + if (updateCfg) { + config.path = ipfsd.repoPath store.set('config', config) } - return createDaemon(config) + return ipfsd } async function run () { diff --git a/src/utils/daemon.js b/src/utils/daemon.js index 159443731..85d754652 100644 --- a/src/utils/daemon.js +++ b/src/utils/daemon.js @@ -1,5 +1,4 @@ import IPFSFactory from 'ipfsd-ctl' -import fs from 'fs-extra' export default async function createDaemon (opts) { opts.type = opts.type || 'go' @@ -11,7 +10,6 @@ export default async function createDaemon (opts) { throw new Error(`${opts.type} connection is not supported yet`) } - const init = !(await fs.pathExists(opts.path)) || fs.readdirSync(opts.path).length === 0 const factory = IPFSFactory.create({ type: opts.type }) const ipfsd = await new Promise((resolve, reject) => { @@ -21,7 +19,7 @@ export default async function createDaemon (opts) { repoPath: opts.path }, (e, ipfsd) => { if (e) return reject(e) - if (ipfsd.initialized || !init) { + if (ipfsd.initialized) { return resolve(ipfsd) }