From b97fce699bc2f9caba3a9621a8c15c35854cfc8c Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 7 Aug 2024 15:49:14 +0200 Subject: [PATCH] Use default user's cache dir instead of tmp for build cache --- commands/service_compile_test.go | 2 +- internal/cli/configuration/configuration.go | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/commands/service_compile_test.go b/commands/service_compile_test.go index 11a47a1fe3f..3eeb4521f1e 100644 --- a/commands/service_compile_test.go +++ b/commands/service_compile_test.go @@ -24,8 +24,8 @@ import ( ) func TestGenBuildPath(t *testing.T) { - want := paths.TempDir().Join("arduino", "sketches", "ACBD18DB4CC2F85CEDEF654FCCC4A4D8") srv := NewArduinoCoreServer().(*arduinoCoreServerImpl) + want := srv.settings.GetBuildCachePath().Join("sketches", "ACBD18DB4CC2F85CEDEF654FCCC4A4D8") act := srv.getDefaultSketchBuildPath(&sketch.Sketch{FullPath: paths.New("foo")}, nil) assert.True(t, act.EquivalentTo(want)) assert.Equal(t, "ACBD18DB4CC2F85CEDEF654FCCC4A4D8", (&sketch.Sketch{FullPath: paths.New("foo")}).Hash()) diff --git a/internal/cli/configuration/configuration.go b/internal/cli/configuration/configuration.go index 571ed155061..134efdfdaf6 100644 --- a/internal/cli/configuration/configuration.go +++ b/internal/cli/configuration/configuration.go @@ -103,7 +103,14 @@ func getDefaultUserDir() string { // getDefaultBuildCacheDir returns the full path to the default build cache folder func getDefaultBuildCacheDir() string { - return paths.TempDir().Join("arduino").String() + var cacheDir *paths.Path + if p, err := os.UserCacheDir(); err == nil { + cacheDir = paths.New(p) + } else { + // fallback to /tmp + cacheDir = paths.TempDir() + } + return cacheDir.Join("arduino").String() } // FindConfigFlagsInArgsOrFallbackOnEnv returns the config file path using the