Skip to content

Commit 1ce4abe

Browse files
[skip-changelog] Recover from interrupted builtin tool installation (#2107)
* Recover from failed builtin tools installation * Add tests for the changes
1 parent 5f03cb9 commit 1ce4abe

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

Diff for: arduino/cores/packagemanager/loader_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ arduino_zero_edbg.serial.disableRTS=true
170170
func TestLoadDiscoveries(t *testing.T) {
171171
// Create all the necessary data to load discoveries
172172
fakePath := paths.New("fake-path")
173+
require.NoError(t, fakePath.Join("LICENSE").MkdirAll())
174+
defer fakePath.RemoveAll()
173175

174176
createTestPackageManager := func() *PackageManager {
175177
pmb := NewBuilder(fakePath, fakePath, fakePath, fakePath, "test")
@@ -277,6 +279,8 @@ func TestLoadDiscoveries(t *testing.T) {
277279
require.Contains(t, discoveries, "teensy")
278280
pmeRelease()
279281
}
282+
283+
require.NoError(t, fakePath.RemoveAll())
280284
}
281285

282286
func TestConvertUploadToolsToPluggableDiscovery(t *testing.T) {

Diff for: arduino/cores/packagemanager/package_manager_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,8 @@ func TestPackageManagerClear(t *testing.T) {
457457
func TestFindToolsRequiredFromPlatformRelease(t *testing.T) {
458458
// Create all the necessary data to load discoveries
459459
fakePath := paths.New("fake-path")
460+
require.NoError(t, fakePath.Join("LICENSE").MkdirAll())
461+
defer fakePath.RemoveAll()
460462

461463
pmb := NewBuilder(fakePath, fakePath, fakePath, fakePath, "test")
462464
pack := pmb.GetOrCreatePackage("arduino")

Diff for: arduino/cores/tools.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,11 @@ func (tool *Tool) String() string {
106106

107107
// IsInstalled returns true if the ToolRelease is installed
108108
func (tr *ToolRelease) IsInstalled() bool {
109-
return tr.InstallDir != nil
109+
if tr.InstallDir == nil {
110+
return false
111+
}
112+
dirContent, _ := tr.InstallDir.ReadDir()
113+
return dirContent.Len() != 0
110114
}
111115

112116
func (tr *ToolRelease) String() string {

Diff for: internal/integrationtest/board/board_test.go

+24
Original file line numberDiff line numberDiff line change
@@ -558,3 +558,27 @@ func TestBoardSearchWithOutdatedCore(t *testing.T) {
558558
// Installed version must be older than latest
559559
require.True(t, installedVersion.LessThan(latestVersion))
560560
}
561+
562+
func TestBoardListWithFailedBuiltinInstallation(t *testing.T) {
563+
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
564+
defer env.CleanUp()
565+
566+
_, _, err := cli.Run("core", "update-index")
567+
require.NoError(t, err)
568+
569+
// board list to install builtin tools
570+
_, _, err = cli.Run("board", "list")
571+
require.NoError(t, err)
572+
573+
// remove files from serial-discovery directory to simulate a failed installation
574+
serialDiscovery, err := cli.DataDir().Join("packages", "builtin", "tools", "serial-discovery").ReadDir()
575+
require.NoError(t, err)
576+
require.NoError(t, serialDiscovery[0].Join("LICENSE.txt").Remove())
577+
require.NoError(t, serialDiscovery[0].Join("serial-discovery.exe").Remove())
578+
579+
// board list should install serial-discovery again
580+
stdout, stderr, err := cli.Run("board", "list")
581+
require.NoError(t, err)
582+
require.Empty(t, stderr)
583+
require.Contains(t, string(stdout), "Downloading missing tool builtin:serial-discovery")
584+
}

0 commit comments

Comments
 (0)