Skip to content

Commit 98dab40

Browse files
authored
Fixed IDE bundle detection (#730)
The portable condition was wrong (it checked for 'non-existance' instead of 'existance'). I've replaced all the conditions with the more readable path.Exist method.
1 parent d3f2dec commit 98dab40

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

Diff for: configuration/configuration.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"strings"
2323

2424
"github.com/arduino/arduino-cli/cli/feedback"
25+
paths "github.com/arduino/go-paths-helper"
2526
"github.com/arduino/go-win32-utils"
2627
"github.com/sirupsen/logrus"
2728
jww "github.com/spf13/jwalterweatherman"
@@ -151,7 +152,8 @@ func IsBundledInDesktopIDE() bool {
151152
return false
152153
}
153154

154-
ideDir := filepath.Dir(executablePath)
155+
ideDir := paths.New(executablePath).Parent()
156+
logrus.WithField("dir", ideDir).Trace("Candidate IDE directory")
155157

156158
// To determine if the CLI is bundled with an IDE, We check an arbitrary
157159
// number of folders that are part of the IDE install tree
@@ -161,20 +163,21 @@ func IsBundledInDesktopIDE() bool {
161163
}
162164

163165
for _, test := range tests {
164-
if _, err := os.Stat(filepath.Join(ideDir, test)); err != nil {
166+
if !ideDir.Join(test).Exist() {
165167
// the test folder doesn't exist or is not accessible
166168
return false
167169
}
168170
}
169171

170-
// the CLI is bundled in the Arduino IDE
172+
logrus.Info("The CLI is bundled in the Arduino IDE")
171173

172174
// Persist IDE-related config settings
173175
viper.Set("IDE.Bundled", true)
174176
viper.Set("IDE.Directory", ideDir)
175177

176178
// Check whether this is a portable install
177-
if _, err := os.Stat(filepath.Join(ideDir, "portable")); err != nil {
179+
if ideDir.Join("portable").Exist() {
180+
logrus.Info("The IDE installation is 'portable'")
178181
viper.Set("IDE.Portable", true)
179182
}
180183

0 commit comments

Comments
 (0)