diff --git a/src/index.js b/src/index.js index 3f7e9da7..6842b682 100644 --- a/src/index.js +++ b/src/index.js @@ -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) }) } diff --git a/src/stores/version.js b/src/stores/version.js index cf166b82..5d037166 100644 --- a/src/stores/version.js +++ b/src/stores/version.js @@ -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') diff --git a/tests/node-tests.js b/tests/node-tests.js index e3bd9855..03452906 100644 --- a/tests/node-tests.js +++ b/tests/node-tests.js @@ -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