Skip to content

Commit

Permalink
feat: do not cleanup api/repo.lock
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Henrique Dias <[email protected]>
  • Loading branch information
hacdias committed Nov 24, 2018
1 parent 7da9397 commit 6a24cf9
Showing 1 changed file with 0 additions and 34 deletions.
34 changes: 0 additions & 34 deletions src/utils/daemon.js
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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
Expand Down Expand Up @@ -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')
}
}
}

0 comments on commit 6a24cf9

Please sign in to comment.