7
7
"fmt"
8
8
"io"
9
9
"os"
10
- "path"
10
+ "path/filepath "
11
11
"strings"
12
12
13
13
assets "github.com/ipfs/go-ipfs/assets"
@@ -16,9 +16,9 @@ import (
16
16
namesys "github.com/ipfs/go-ipfs/namesys"
17
17
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
18
18
19
- "github.com/ipfs/go-ipfs-cmds"
20
- "github.com/ipfs/go-ipfs-config"
21
- "github.com/ipfs/go-ipfs-files"
19
+ cmds "github.com/ipfs/go-ipfs-cmds"
20
+ config "github.com/ipfs/go-ipfs-config"
21
+ files "github.com/ipfs/go-ipfs-files"
22
22
)
23
23
24
24
const (
@@ -28,6 +28,10 @@ const (
28
28
profileOptionName = "profile"
29
29
)
30
30
31
+ var errRepoExists = errors .New (`ipfs configuration file already exists!
32
+ Reinitializing would overwrite your keys.
33
+ ` )
34
+
31
35
var initCmd = & cmds.Command {
32
36
Helptext : cmds.HelpText {
33
37
Tagline : "Initializes ipfs config file." ,
@@ -102,31 +106,30 @@ environment variable:
102
106
}
103
107
}
104
108
105
- profile , _ := req .Options [profileOptionName ].(string )
106
-
107
- var profiles []string
108
- if profile != "" {
109
- profiles = strings .Split (profile , "," )
110
- }
111
-
109
+ profiles , _ := req .Options [profileOptionName ].(string )
112
110
return doInit (os .Stdout , cctx .ConfigRoot , empty , nBitsForKeypair , profiles , conf )
113
111
},
114
112
}
115
113
116
- var errRepoExists = errors .New (`ipfs configuration file already exists!
117
- Reinitializing would overwrite your keys.
118
- ` )
119
-
120
- func initWithDefaults (out io.Writer , repoRoot string , profile string ) error {
121
- var profiles []string
122
- if profile != "" {
123
- profiles = strings .Split (profile , "," )
114
+ func applyProfiles (conf * config.Config , profiles string ) error {
115
+ if profiles == "" {
116
+ return nil
124
117
}
125
118
126
- return doInit (out , repoRoot , false , nBitsForKeypairDefault , profiles , nil )
119
+ for _ , profile := range strings .Split (profiles , "," ) {
120
+ transformer , ok := config .Profiles [profile ]
121
+ if ! ok {
122
+ return fmt .Errorf ("invalid configuration profile: %s" , profile )
123
+ }
124
+
125
+ if err := transformer .Transform (conf ); err != nil {
126
+ return err
127
+ }
128
+ }
129
+ return nil
127
130
}
128
131
129
- func doInit (out io.Writer , repoRoot string , empty bool , nBitsForKeypair int , confProfiles [] string , conf * config.Config ) error {
132
+ func doInit (out io.Writer , repoRoot string , empty bool , nBitsForKeypair int , confProfiles string , conf * config.Config ) error {
130
133
if _ , err := fmt .Fprintf (out , "initializing IPFS node at %s\n " , repoRoot ); err != nil {
131
134
return err
132
135
}
@@ -147,15 +150,8 @@ func doInit(out io.Writer, repoRoot string, empty bool, nBitsForKeypair int, con
147
150
}
148
151
}
149
152
150
- for _ , profile := range confProfiles {
151
- transformer , ok := config .Profiles [profile ]
152
- if ! ok {
153
- return fmt .Errorf ("invalid configuration profile: %s" , profile )
154
- }
155
-
156
- if err := transformer .Transform (conf ); err != nil {
157
- return err
158
- }
153
+ if err := applyProfiles (conf , confProfiles ); err != nil {
154
+ return err
159
155
}
160
156
161
157
if err := fsrepo .Init (repoRoot , conf ); err != nil {
@@ -175,7 +171,7 @@ func checkWritable(dir string) error {
175
171
_ , err := os .Stat (dir )
176
172
if err == nil {
177
173
// dir exists, make sure we can write to it
178
- testfile := path .Join (dir , "test" )
174
+ testfile := filepath .Join (dir , "test" )
179
175
fi , err := os .Create (testfile )
180
176
if err != nil {
181
177
if os .IsPermission (err ) {
0 commit comments