refactor(repo/fsrepo): use repo to check whether config exists
Brian Tiger Chow committed
Jan 12, 2015 at 11:07 UTC
44f3d95c3b910d0c02f6a4b0a8fbd6b77f326e77
2 files changed
+20
-1
cmd/ipfs/init.go
+2
-1
@@ -18,6 +18,7 @@ import (
18
peer "github.com/jbenet/go-ipfs/p2p/peer"
19
repo "github.com/jbenet/go-ipfs/repo"
20
config "github.com/jbenet/go-ipfs/repo/config"
21
+ "github.com/jbenet/go-ipfs/repo/fsrepo"
22
u "github.com/jbenet/go-ipfs/util"
23
debugerror "github.com/jbenet/go-ipfs/util/debugerror"
24
)
@@ -99,7 +100,7 @@ func doInit(configRoot string, dspathOverride string, force bool, nBitsForKeypai
100
return nil, debugerror.New("Couldn't get home directory path")
101
}
102
102
- if u.FileExists(configFilename) && !force {
103
+ if fsrepo.ConfigIsInitialized(configRoot) && !force {
104
return nil, errCannotInitConfigExists
105
}
106
repo/fsrepo/fsrepo.go
new
+18
@@ -0,0 +1,18 @@
1
+package fsrepo
2
+
3
+import (
4
+ config "github.com/jbenet/go-ipfs/repo/config"
5
+ util "github.com/jbenet/go-ipfs/util"
6
+)
7
+
8
+// ConfigIsInitialized returns true if the config exists in provided |path|.
9
+func ConfigIsInitialized(path string) bool {
10
+ configFilename, err := config.Filename(path)
11
+ if err != nil {
12
+ return false
13
+ }
14
+ if !util.FileExists(configFilename) {
15
+ return false
16
+ }
17
+ return true
18
+}