1616package repertory
1717
1818import (
19+ "os"
1920 "path/filepath"
2021
2122 "github.com/arduino/arduino-cli/cli/feedback"
22- "github.com/arduino/arduino-cli/configuration"
2323 "github.com/gofrs/uuid"
2424 "github.com/spf13/viper"
2525)
@@ -33,22 +33,18 @@ var (
3333)
3434
3535// 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 )
3838 Store .SetConfigName (Name )
3939 Store .SetConfigType (Type )
4040 Store .AddConfigPath (configPath )
41- configFilePath := filepath .Join (configPath , Name )
4241 // Attempt to read config file
4342 if err := Store .ReadInConfig (); err != nil {
4443 // ConfigFileNotFoundError is acceptable, anything else
4544 // should be reported to the user
4645 if _ , ok := err .(viper.ConfigFileNotFoundError ); ok {
4746 generateInstallationData ()
48- err := Store .WriteConfigAs (configFilePath )
49- if err != nil {
50- feedback .Errorf ("Error writing repertory file: %v" , err )
51- }
47+ writeStore (configFilePath )
5248 } else {
5349 feedback .Errorf ("Error reading repertory file: %v" , err )
5450 }
@@ -69,3 +65,16 @@ func generateInstallationData() {
6965 }
7066 Store .Set ("installation.secret" , installationSecret .String ())
7167}
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