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

Initial commit for repoExists #776

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const debug = require('debug')
const defaultRepo = require('./default-repo')

const components = require('./components')
const utils = require('./utils')

class IPFS {
constructor (configOpts) {
Expand Down Expand Up @@ -62,6 +63,7 @@ class IPFS {
this.bitswap = components.bitswap(this)
this.ping = components.ping(this)
this.pubsub = components.pubsub(this)
this.repoExists = utils.repoExists(this)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding a new utility function, we could just assign this.repoExists to repoInstance.exists and all should work. Would be less duplicated code + tests.

Copy link
Contributor Author

@aphelionz aphelionz Mar 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll give that a shot. The test should still run against this.repoExists though, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I would say we should still test it, to be sure. Better safe than sorry


if (configOpts.EXPERIMENTAL.pubsub) {
this.log('EXPERIMENTAL pubsub is enabled')
Expand Down
12 changes: 12 additions & 0 deletions src/core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,16 @@ exports.ifRepoExists = (repo, cb) => {
})
}

exports.repoExists = (self) => {
return (cb) => {
self._repo.exists((err, exists) => {
if (err) {
return cb(err)
}

cb(err, exists)
})
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's converge repoExists and ifRepoExists and make the converged function async (with callbacks and a promisify wrapper), the reason why it needs to be async is because the repo might be over a wire (like a S3 bucket).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @aphelionz , how is the development of this feature?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@diasdavid Gonna push some more commit(s) today.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if you need any help :)


exports.OFFLINE_ERROR = new Error('This command must be run in online mode. Try running \'ipfs daemon\' first.')
20 changes: 20 additions & 0 deletions test/core/init.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,24 @@ describe('init', () => {
})
})
})

it('checks if existing repo exists', (done) => {
ipfs.init({ bits: 1024, emptyRepo: true }, (err) => {
expect(err).to.not.exist

ipfs.repoExists((err, exists) => {
expect(err).to.not.exist
expect(exists).to.be.true
done()
})
})
})

it('checks if nonexistant repo exists', (done) => {
ipfs.repoExists((err, exists) => {
expect(err).to.not.exist
expect(exists).to.be.false
done()
})
})
})