Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
add daemon lock unlock
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Feb 20, 2016
1 parent 39f518c commit 8d34c83
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
15 changes: 13 additions & 2 deletions src/http-api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,26 @@
const Hapi = require('hapi')
const IPFS = require('../ipfs-core')
const debug = require('debug')
const fs = require('fs')
const os = require('os')
const log = debug('api')
log.error = debug('api:error')

exports = module.exports

exports.start = callback => {
// start IPFS and exports.ipfs = new IPFS()
const repoPath = process.env.IPFS_PATH || os.homedir() + '/.ipfs'

exports.start = callback => {
const ipfs = exports.ipfs = new IPFS()

try {
fs.statSync(repoPath + '/api')
console.log('This repo is currently being used by another daemon')
process.exit(1)
} catch (err) {
fs.writeFileSync(repoPath + '/api', 'api is on by js-ipfs')
}

ipfs.config.show((err, config) => {
if (err) {
return callback(err)
Expand Down Expand Up @@ -50,5 +60,6 @@ exports.start = callback => {
}

exports.stop = callback => {
fs.unlinkSync(repoPath + '/api')
exports.server.stop(callback)
}
6 changes: 1 addition & 5 deletions src/ipfs-core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ function IPFS (repo) {
const blockS = new BlockService(repo)
const dagS = new DAGService(blockS)

this.daemon = callback => {
// 1. read repo to get peer data
}

this.version = (opts, callback) => {
if (typeof opts === 'function') {
callback = opts
Expand Down Expand Up @@ -113,7 +109,7 @@ function IPFS (repo) {
return false
} else { return true }
})
repo.config.set(config, err => {
repo.config.set(config, (err) => {
if (err) { return callback(err) }
callback()
})
Expand Down

0 comments on commit 8d34c83

Please sign in to comment.