Skip to content

Commit

Permalink
Merge pull request #30 from noffle/init
Browse files Browse the repository at this point in the history
No longer considers a non-existant repo an error.
  • Loading branch information
daviddias committed Mar 19, 2016
2 parents 45fcfcc + 4076a3c commit 10b9f29
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
17 changes: 10 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@ exports = module.exports = Repo

function Repo (repoPath, options) {
this.init = (config, callback) => {
if (this.exists()) {
throw new Error('Repo already exists')
}
this.exists((err, exists) => {
if (err) { throw err }
if (exists) { throw new Error('Repo already exists') }
throw new Error('not implemented')
})
}

this.locks = stores
.locks
.setUp(repoPath, options.stores.locks)

this.exists = callback => {
this.version.get((err, version) => {
this.exists = (callback) => {
this.version.exists((err, exists) => {
if (err) {
return callback(new Error('Repo does not exist'))
callback(new Error('repo does not exist'), false)
} else {
callback(null, exists)
}
callback(null, true)
})
}

Expand Down
3 changes: 3 additions & 0 deletions src/stores/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ exports.setUp = (basePath, blobStore, locks) => {
var store = blobStore(basePath)

return {
exists: callback => {
store.exists('version', callback)
},
get: callback => {
store
.createReadStream('version')
Expand Down
2 changes: 1 addition & 1 deletion tests/node-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const rimraf = require('rimraf')

const IPFSRepo = require('../src')

describe('IPFS Repo Testson on Node.js', () => {
describe('IPFS Repo Tests on on Node.js', () => {
const testRepoPath = __dirname + '/test-repo'
const date = Date.now().toString()
const repoPath = testRepoPath + date
Expand Down

0 comments on commit 10b9f29

Please sign in to comment.