Skip to content

Commit 2964f32

Browse files
committed
NewConstPath now keeps labels and autocreation of folders
1 parent 45b1ad9 commit 2964f32

File tree

4 files changed

+13
-15
lines changed

4 files changed

+13
-15
lines changed

configs/env_vars_serializer.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ func LoadFromEnv() {
4141
ProxyType = p
4242
}
4343
if dir, has := os.LookupEnv("ARDUINO_SKETCHBOOK_DIR"); has {
44-
SketchbookFolder = pathutils.NewConstPath(dir)
44+
SketchbookFolder = pathutils.NewConstPath("Sketchbook", dir, true)
4545
ArduinoHomeFolder = SketchbookFolder
4646
}
4747
if dir, has := os.LookupEnv("ARDUINO_DATA_DIR"); has {
48-
ArduinoDataFolder = pathutils.NewConstPath(dir)
48+
ArduinoDataFolder = pathutils.NewConstPath("Arduino Data", dir, true)
4949
}
5050
}

configs/preferences_txt_serializer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func LoadFromDesktopIDEPreferences() error {
9999
return err
100100
}
101101
if dir, has := props["sketchbook.path"]; has {
102-
SketchbookFolder = pathutils.NewConstPath(dir)
102+
SketchbookFolder = pathutils.NewConstPath("Sketchbook", dir, true)
103103
ArduinoHomeFolder = SketchbookFolder
104104
}
105105
if URLs, has := props["boardsmanager.additional.urls"]; has {

configs/yaml_serializer.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ func LoadFromYAML(path string) error {
7070
}
7171

7272
if ret.ArduinoDataFolder != "" {
73-
ArduinoDataFolder = pathutils.NewConstPath(ret.ArduinoDataFolder)
73+
ArduinoDataFolder = pathutils.NewConstPath("Arduino Data", ret.ArduinoDataFolder, true)
7474
}
7575
if ret.SketchbookPath != "" {
76-
SketchbookFolder = pathutils.NewConstPath(ret.SketchbookPath)
76+
SketchbookFolder = pathutils.NewConstPath("Sketchbook", ret.SketchbookPath, true)
7777
}
7878
if ret.ProxyType != "" {
7979
ProxyType = ret.ProxyType

pathutils/pathutils.go

+8-10
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,14 @@ type Path interface {
4343

4444
// NewConstPath creates a constant Path that always returns the specified
4545
// path, errors will always be nil
46-
func NewConstPath(path string) Path {
47-
return &constPath{Path: path}
46+
func NewConstPath(label string, path string, createIfMissing bool) Path {
47+
return &basicPath{
48+
Label: label,
49+
ProviderFunction: func() (string, error) {
50+
return path, nil
51+
},
52+
CreateIfMissing: createIfMissing,
53+
}
4854
}
4955

5056
// NewPath return a Path object that use the providerFunction to determine
@@ -70,14 +76,6 @@ func NewSubPath(label string, path Path, subPath string, createIfMissing bool) P
7076
}
7177
}
7278

73-
type constPath struct {
74-
Path string
75-
}
76-
77-
func (p *constPath) Get() (string, error) {
78-
return p.Path, nil
79-
}
80-
8179
type basicPath struct {
8280
Label string
8381
ProviderFunction func() (string, error)

0 commit comments

Comments
 (0)