Skip to content

Commit 29c1182

Browse files
committed
Added DownloadsDir configuration and env var
1 parent 3819f27 commit 29c1182

File tree

4 files changed

+45
-9
lines changed

4 files changed

+45
-9
lines changed

commands/commands_test.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ import (
2626
"testing"
2727

2828
"github.com/arduino/arduino-cli/commands/root"
29-
"github.com/arduino/go-paths-helper"
29+
paths "github.com/arduino/go-paths-helper"
3030
"github.com/bouk/monkey"
3131
"github.com/stretchr/testify/assert"
3232
"github.com/stretchr/testify/require"
33-
"go.bug.st/relaxed-semver"
33+
semver "go.bug.st/relaxed-semver"
3434
)
3535

3636
// Redirecting stdOut so we can analyze output line by
@@ -110,11 +110,28 @@ func executeWithArgs(t *testing.T, args ...string) (int, []byte) {
110110
return exitCode, output
111111
}
112112

113+
var currDownloadDir *paths.Path
114+
115+
func useSharedDownloadDir(t *testing.T) func() {
116+
tmp := paths.TempDir().Join("arduino-cli-test-staging")
117+
err := tmp.MkdirAll()
118+
require.NoError(t, err, "making shared staging dir")
119+
os.Setenv("ARDUINO_DOWNLOADS_DIR", tmp.String())
120+
currDownloadDir = tmp
121+
fmt.Printf("ARDUINO_DOWNLOADS_DIR = %s\n", os.Getenv("ARDUINO_DOWNLOADS_DIR"))
122+
123+
return func() {
124+
os.Unsetenv("ARDUINO_DOWNLOADS_DIR")
125+
currDownloadDir = nil
126+
fmt.Printf("ARDUINO_DOWNLOADS_DIR = %s\n", os.Getenv("ARDUINO_DOWNLOADS_DIR"))
127+
}
128+
}
129+
113130
var currDataDir *paths.Path
114131

115132
func makeTempDataDir(t *testing.T) func() {
116133
tmp, err := paths.MkTempDir("", "test")
117-
require.NoError(t, err, "making temporary staging dir")
134+
require.NoError(t, err, "making temporary data dir")
118135
os.Setenv("ARDUINO_DATA_DIR", tmp.String())
119136
currDataDir = tmp
120137
fmt.Printf("ARDUINO_DATA_DIR = %s\n", os.Getenv("ARDUINO_DATA_DIR"))

configs/configuration.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"fmt"
2323
"net/url"
2424

25-
"github.com/arduino/go-paths-helper"
25+
paths "github.com/arduino/go-paths-helper"
2626
)
2727

2828
// Configuration contains a running configuration
@@ -39,6 +39,10 @@ type Configuration struct {
3939
// ArduinoIDEDirectory is the directory of the Arduino IDE if the CLI runs together with it.
4040
ArduinoIDEDirectory *paths.Path
4141

42+
// downloadsDir is the directory where the package files are downloaded and cached.
43+
// Use DownloadsDir() method to retrieve it.
44+
downloadsDir *paths.Path
45+
4246
// IDEBundledCheckResult contains the result of the check to see if the CLI is bundled with the IDE:
4347
// the field is true if the CLI is bundled with the Arduino IDE, false if the CLI is running
4448
// standalone or nil if the detection has not been performed.
@@ -94,6 +98,9 @@ func (config *Configuration) PackagesDir() *paths.Path {
9498

9599
// DownloadsDir returns the directory for archive downloads.
96100
func (config *Configuration) DownloadsDir() *paths.Path {
101+
if config.downloadsDir != nil {
102+
return config.downloadsDir
103+
}
97104
return config.DataDir.Join("staging")
98105
}
99106

configs/env_vars_serializer.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,7 @@ func (config *Configuration) LoadFromEnv() {
3434
if dir, has := os.LookupEnv("ARDUINO_DATA_DIR"); has {
3535
config.DataDir = paths.New(dir)
3636
}
37+
if dir, has := os.LookupEnv("ARDUINO_DOWNLOADS_DIR"); has {
38+
config.downloadsDir = paths.New(dir)
39+
}
3740
}

configs/yaml_serializer.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ import (
2828
)
2929

3030
type yamlConfig struct {
31-
ProxyType string `yaml:"proxy_type"`
32-
ProxyManualConfig *yamlProxyConfig `yaml:"manual_configs,omitempty"`
33-
SketchbookPath string `yaml:"sketchbook_path,omitempty"`
34-
ArduinoDataDir string `yaml:"arduino_data,omitempty"`
35-
BoardsManager *yamlBoardsManagerConfig `yaml:"board_manager"`
31+
ProxyType string `yaml:"proxy_type"`
32+
ProxyManualConfig *yamlProxyConfig `yaml:"manual_configs,omitempty"`
33+
SketchbookPath string `yaml:"sketchbook_path,omitempty"`
34+
ArduinoDataDir string `yaml:"arduino_data,omitempty"`
35+
ArduinoDownloadsDir string `yaml:"arduino_downloads_dir,omitempty"`
36+
BoardsManager *yamlBoardsManagerConfig `yaml:"board_manager"`
3637
}
3738

3839
type yamlBoardsManagerConfig struct {
@@ -66,6 +67,11 @@ func (config *Configuration) LoadFromYAML(path *paths.Path) error {
6667
if ret.SketchbookPath != "" {
6768
config.SketchbookDir = paths.New(ret.SketchbookPath)
6869
}
70+
if ret.ArduinoDownloadsDir != "" {
71+
config.downloadsDir = paths.New(ret.ArduinoDownloadsDir)
72+
} else {
73+
config.downloadsDir = nil
74+
}
6975
if ret.ProxyType != "" {
7076
config.ProxyType = ret.ProxyType
7177
if ret.ProxyManualConfig != nil {
@@ -96,6 +102,9 @@ func (config *Configuration) SerializeToYAML() ([]byte, error) {
96102
if config.DataDir != nil {
97103
c.ArduinoDataDir = config.DataDir.String()
98104
}
105+
if config.downloadsDir != nil {
106+
c.ArduinoDownloadsDir = config.downloadsDir.String()
107+
}
99108
c.ProxyType = config.ProxyType
100109
if config.ProxyType == "manual" {
101110
c.ProxyManualConfig = &yamlProxyConfig{

0 commit comments

Comments
 (0)