-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Loosen up init requirements: accept already initialised repos #808
Conversation
Currently failing with:
|
src/core/boot.js
Outdated
tasks.push((cb) => self.init(initOptions, cb)) | ||
tasks.push((cb) => { | ||
console.log('Doing init') | ||
self._repo.exists((err, exists) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this doesn't make much sense as it's the same thing as in the else branch
src/core/boot.js
Outdated
if (err) cb(err) | ||
console.log('exists', err, exists) | ||
if (exists) { | ||
cb(null, true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you need to call maybeOpenRepo if you don't do init
src/core/boot.js
Outdated
@@ -49,7 +49,16 @@ module.exports = (self) => { | |||
|
|||
if (doInit) { | |||
self.log('boot:doInit') | |||
tasks.push((cb) => self.init(initOptions, cb)) | |||
tasks.push((cb) => { | |||
self._repo.exists((err, exists) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are still doing the same call twice in the if (doInit)
. you can just call repo.exists
and do the if doInit check later down
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like this
self._repo.exists((err, hasRepo) => {
if (err) {
return done(err)
}
if (doInit && !hasRepo) {
tasks.push((cb) => self.init(initOptions, cb))
}
if (hasRepo) {
tasks.push(maybeOpenRepo)
}
if (setConfig) {
// ...
})
src/core/boot.js
Outdated
tasks.push((cb) => self.init(initOptions, cb)) | ||
tasks.push((cb) => { | ||
self._repo.exists((err, exists) => { | ||
if (err) cb(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs to return and please on with braces on multiple lines
Ready to be checked and eventually merged now :) |
@victorbjelkholm did you see my comments? |
43f8c3f
to
4f763ef
Compare
src/core/boot.js
Outdated
if (repoExists) { | ||
tasks.push(maybeOpenRepo) | ||
} | ||
next(null, repoExists) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for the next function anymore :)
1e440f6
to
bf93bc5
Compare
src/core/boot.js
Outdated
} | ||
if (repoExists) { | ||
tasks.push(maybeOpenRepo) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is still a bug, next
needs to be called with hasRepo
not true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dignifiedquire I've tried that and then I get bunch of failures
WARNING, trying to set config on uninitialized repo, maybe forgot to set "init: true"
WARNING, trying to start ipfs node on uninitialized repo, maybe forgot to set "init: true"
src/core/boot.js
Outdated
if (doInit && !repoExists) { | ||
tasks.push((cb) => self.init(initOptions, cb)) | ||
} | ||
if (repoExists) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to check for !doInit as well
series(tasks, done) | ||
} | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 to the whole commit :)
f90dc4a
to
26e6290
Compare
This PR will make it so if you start a node twice with the same path, it won't crash when trying to initialize a new repo. Synonym with doing
ipfs daemon --init
with go-ipfs in terminal.