Skip to content

Commit c8d0ce9

Browse files
committed
Created configuration defaults for build_cache.path setting
1 parent 47092d8 commit c8d0ce9

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

commands/service_compile.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,8 @@ func (s *arduinoCoreServerImpl) Compile(req *rpc.CompileRequest, stream rpc.Ardu
196196
return &cmderrors.PermissionDeniedError{Message: i18n.Tr("Cannot create build cache directory"), Cause: err}
197197
}
198198
buildCachePath = p
199-
} else if p, ok := s.settings.GetBuildCachePath(); ok {
200-
buildCachePath = p
201199
} else {
202-
buildCachePath = paths.TempDir().Join("arduino")
200+
buildCachePath = s.settings.GetBuildCachePath()
203201
}
204202
if err := buildCachePath.MkdirAll(); err != nil {
205203
return &cmderrors.PermissionDeniedError{Message: i18n.Tr("Cannot create build cache directory"), Cause: err}

internal/cli/configuration/build_cache.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,11 @@ func (s *Settings) GetBuildCacheTTL() time.Duration {
3838
}
3939

4040
// GetBuildCachePath returns the path to the build cache.
41-
func (s *Settings) GetBuildCachePath() (*paths.Path, bool) {
42-
p, ok, _ := s.GetStringOk("build_cache.path")
43-
if !ok {
44-
return nil, false
41+
func (s *Settings) GetBuildCachePath() *paths.Path {
42+
if p, ok, _ := s.GetStringOk("build_cache.path"); ok {
43+
return paths.New(p)
4544
}
46-
return paths.New(p), true
45+
return paths.New(s.Defaults.GetString("build_cache.path"))
4746
}
4847

4948
// GetBuildCacheExtraPaths returns the extra paths to the build cache.

internal/cli/configuration/configuration.go

+5
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ func getDefaultUserDir() string {
101101
}
102102
}
103103

104+
// getDefaultBuildCacheDir returns the full path to the default build cache folder
105+
func getDefaultBuildCacheDir() string {
106+
return paths.TempDir().Join("arduino").String()
107+
}
108+
104109
// FindConfigFlagsInArgsOrFallbackOnEnv returns the config file path using the
105110
// argument '--config-file' (if specified), if empty looks for the ARDUINO_CONFIG_FILE env,
106111
// or looking in the current working dir

internal/cli/configuration/defaults.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func SetDefaults(settings *Settings) {
5252
setDefaultValueAndKeyTypeSchema("sketch.always_export_binaries", false)
5353
setDefaultValueAndKeyTypeSchema("build_cache.ttl", (time.Hour * 24 * 30).String())
5454
setDefaultValueAndKeyTypeSchema("build_cache.compilations_before_purge", uint(10))
55-
setKeyTypeSchema("build_cache.path", "")
55+
setDefaultValueAndKeyTypeSchema("build_cache.path", getDefaultBuildCacheDir())
5656
setKeyTypeSchema("build_cache.extra_paths", []string{})
5757

5858
// daemon settings

0 commit comments

Comments
 (0)