16
16
package repertory
17
17
18
18
import (
19
+ "os"
19
20
"path/filepath"
20
21
21
22
"github.com/arduino/arduino-cli/cli/feedback"
22
- "github.com/arduino/arduino-cli/configuration"
23
23
"github.com/gofrs/uuid"
24
24
"github.com/spf13/viper"
25
25
)
@@ -33,22 +33,18 @@ var (
33
33
)
34
34
35
35
// Configure configures the Read Only config storage
36
- func Init() {
37
- configPath := configuration.GetDefaultArduinoDataDir( )
36
+ func Init(configPath string ) {
37
+ configFilePath := filepath.Join(configPath, Name )
38
38
Store.SetConfigName(Name)
39
39
Store.SetConfigType(Type)
40
40
Store.AddConfigPath(configPath)
41
- configFilePath := filepath.Join(configPath, Name)
42
41
// Attempt to read config file
43
42
if err := Store.ReadInConfig(); err != nil {
44
43
// ConfigFileNotFoundError is acceptable, anything else
45
44
// should be reported to the user
46
45
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
47
46
generateInstallationData()
48
- err := Store.WriteConfigAs(configFilePath)
49
- if err != nil {
50
- feedback.Errorf("Error writing repertory file: %v", err)
51
- }
47
+ writeStore(configFilePath)
52
48
} else {
53
49
feedback.Errorf("Error reading repertory file: %v", err)
54
50
}
@@ -69,3 +65,16 @@ func generateInstallationData() {
69
65
}
70
66
Store.Set("installation.secret", installationSecret.String())
71
67
}
68
+
69
+ func writeStore(configFilePath string) {
70
+ configPath := filepath.Dir(configFilePath)
71
+ // Create dir if not present
72
+ if _, err := os.Stat(configPath); os.IsNotExist(err) {
73
+ os.MkdirAll(configPath, 0755)
74
+ }
75
+ // Create file if not present
76
+ err := Store.WriteConfigAs(configFilePath)
77
+ if err != nil {
78
+ feedback.Errorf("Error writing repertory file: %v", err)
79
+ }
80
+ }
0 commit comments