refactor(repo/fsrepo): use repo to check whether config exists

This commit is contained in:
Brian Tiger Chow 2015-01-12 11:07:27 -08:00
parent 5b3164de5c
commit 44f3d95c3b
2 changed files with 20 additions and 1 deletions

View File

@ -18,6 +18,7 @@ import (
peer "github.com/jbenet/go-ipfs/p2p/peer"
repo "github.com/jbenet/go-ipfs/repo"
config "github.com/jbenet/go-ipfs/repo/config"
"github.com/jbenet/go-ipfs/repo/fsrepo"
u "github.com/jbenet/go-ipfs/util"
debugerror "github.com/jbenet/go-ipfs/util/debugerror"
)
@ -99,7 +100,7 @@ func doInit(configRoot string, dspathOverride string, force bool, nBitsForKeypai
return nil, debugerror.New("Couldn't get home directory path")
}
if u.FileExists(configFilename) && !force {
if fsrepo.ConfigIsInitialized(configRoot) && !force {
return nil, errCannotInitConfigExists
}

18
repo/fsrepo/fsrepo.go Normal file
View File

@ -0,0 +1,18 @@
package fsrepo
import (
config "github.com/jbenet/go-ipfs/repo/config"
util "github.com/jbenet/go-ipfs/util"
)
// ConfigIsInitialized returns true if the config exists in provided |path|.
func ConfigIsInitialized(path string) bool {
configFilename, err := config.Filename(path)
if err != nil {
return false
}
if !util.FileExists(configFilename) {
return false
}
return true
}