Unverified Commit 1ce4abef authored by MatteoPologruto's avatar MatteoPologruto Committed by GitHub

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

* Recover from failed builtin tools installation

* Add tests for the changes
parent 5f03cb95
......@@ -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")
......@@ -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) {
......
......@@ -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")
......
......@@ -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 {
......
......@@ -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")
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment