mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 10:27:46 +08:00
refactor(repo/fsrepo): use repo to check whether config exists
This commit is contained in:
parent
5b3164de5c
commit
44f3d95c3b
@ -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
18
repo/fsrepo/fsrepo.go
Normal 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
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user