Skip to content

Commit 10b9f29

Browse files
committed
Merge pull request #30 from noffle/init
No longer considers a non-existant repo an error.
2 parents 45fcfcc + 4076a3c commit 10b9f29

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

src/index.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,24 @@ exports = module.exports = Repo
44

55
function Repo (repoPath, options) {
66
this.init = (config, callback) => {
7-
if (this.exists()) {
8-
throw new Error('Repo already exists')
9-
}
7+
this.exists((err, exists) => {
8+
if (err) { throw err }
9+
if (exists) { throw new Error('Repo already exists') }
10+
throw new Error('not implemented')
11+
})
1012
}
1113

1214
this.locks = stores
1315
.locks
1416
.setUp(repoPath, options.stores.locks)
1517

16-
this.exists = callback => {
17-
this.version.get((err, version) => {
18+
this.exists = (callback) => {
19+
this.version.exists((err, exists) => {
1820
if (err) {
19-
return callback(new Error('Repo does not exist'))
21+
callback(new Error('repo does not exist'), false)
22+
} else {
23+
callback(null, exists)
2024
}
21-
callback(null, true)
2225
})
2326
}
2427

src/stores/version.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ exports.setUp = (basePath, blobStore, locks) => {
66
var store = blobStore(basePath)
77

88
return {
9+
exists: callback => {
10+
store.exists('version', callback)
11+
},
912
get: callback => {
1013
store
1114
.createReadStream('version')

tests/node-tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const rimraf = require('rimraf')
66

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

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

0 commit comments

Comments
 (0)