Skip to content

[skip-changelog] Recover from interrupted builtin tool installation #2107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions arduino/cores/packagemanager/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ arduino_zero_edbg.serial.disableRTS=true
func TestLoadDiscoveries(t *testing.T) {
// Create all the necessary data to load discoveries
fakePath := paths.New("fake-path")
require.NoError(t, fakePath.Join("LICENSE").MkdirAll())
defer fakePath.RemoveAll()

createTestPackageManager := func() *PackageManager {
pmb := NewBuilder(fakePath, fakePath, fakePath, fakePath, "test")
Expand Down Expand Up @@ -277,6 +279,8 @@ func TestLoadDiscoveries(t *testing.T) {
require.Contains(t, discoveries, "teensy")
pmeRelease()
}

require.NoError(t, fakePath.RemoveAll())
}

func TestConvertUploadToolsToPluggableDiscovery(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions arduino/cores/packagemanager/package_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,8 @@ func TestPackageManagerClear(t *testing.T) {
func TestFindToolsRequiredFromPlatformRelease(t *testing.T) {
// Create all the necessary data to load discoveries
fakePath := paths.New("fake-path")
require.NoError(t, fakePath.Join("LICENSE").MkdirAll())
defer fakePath.RemoveAll()

pmb := NewBuilder(fakePath, fakePath, fakePath, fakePath, "test")
pack := pmb.GetOrCreatePackage("arduino")
Expand Down
6 changes: 5 additions & 1 deletion arduino/cores/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ func (tool *Tool) String() string {

// IsInstalled returns true if the ToolRelease is installed
func (tr *ToolRelease) IsInstalled() bool {
return tr.InstallDir != nil
if tr.InstallDir == nil {
return false
}
dirContent, _ := tr.InstallDir.ReadDir()
return dirContent.Len() != 0
}

func (tr *ToolRelease) String() string {
Expand Down
24 changes: 24 additions & 0 deletions internal/integrationtest/board/board_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,3 +558,27 @@ func TestBoardSearchWithOutdatedCore(t *testing.T) {
// Installed version must be older than latest
require.True(t, installedVersion.LessThan(latestVersion))
}

func TestBoardListWithFailedBuiltinInstallation(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()

_, _, err := cli.Run("core", "update-index")
require.NoError(t, err)

// board list to install builtin tools
_, _, err = cli.Run("board", "list")
require.NoError(t, err)

// remove files from serial-discovery directory to simulate a failed installation
serialDiscovery, err := cli.DataDir().Join("packages", "builtin", "tools", "serial-discovery").ReadDir()
require.NoError(t, err)
require.NoError(t, serialDiscovery[0].Join("LICENSE.txt").Remove())
require.NoError(t, serialDiscovery[0].Join("serial-discovery.exe").Remove())

// board list should install serial-discovery again
stdout, stderr, err := cli.Run("board", "list")
require.NoError(t, err)
require.Empty(t, stderr)
require.Contains(t, string(stdout), "Downloading missing tool builtin:serial-discovery")
}