Unverified Commit a58d5adb authored by Luca Bianconi's avatar Luca Bianconi Committed by GitHub

fix: scan libraries on install (#2037)

parent 18973684
...@@ -64,6 +64,7 @@ func (lm *LibrariesManager) InstallPrerequisiteCheck(name string, version *semve ...@@ -64,6 +64,7 @@ func (lm *LibrariesManager) InstallPrerequisiteCheck(name string, version *semve
return nil, err return nil, err
} }
lm.RescanLibraries()
libs := lm.FindByReference(&librariesindex.Reference{Name: name}, installLocation) libs := lm.FindByReference(&librariesindex.Reference{Name: name}, installLocation)
if len(libs) > 1 { if len(libs) > 1 {
......
...@@ -132,6 +132,7 @@ func (lm *LibrariesManager) AddPlatformReleaseLibrariesDir(plaftormRelease *core ...@@ -132,6 +132,7 @@ func (lm *LibrariesManager) AddPlatformReleaseLibrariesDir(plaftormRelease *core
// RescanLibraries reload all installed libraries in the system. // RescanLibraries reload all installed libraries in the system.
func (lm *LibrariesManager) RescanLibraries() []*status.Status { func (lm *LibrariesManager) RescanLibraries() []*status.Status {
lm.clearLibraries()
statuses := []*status.Status{} statuses := []*status.Status{}
for _, dir := range lm.LibrariesDir { for _, dir := range lm.LibrariesDir {
if errs := lm.LoadLibrariesFromDir(dir); len(errs) > 0 { if errs := lm.LoadLibrariesFromDir(dir); len(errs) > 0 {
...@@ -217,3 +218,9 @@ func (lm *LibrariesManager) FindByReference(libRef *librariesindex.Reference, in ...@@ -217,3 +218,9 @@ func (lm *LibrariesManager) FindByReference(libRef *librariesindex.Reference, in
} }
return alternatives.FilterByVersionAndInstallLocation(libRef.Version, installLocation) return alternatives.FilterByVersionAndInstallLocation(libRef.Version, installLocation)
} }
func (lm *LibrariesManager) clearLibraries() {
for k := range lm.Libraries {
delete(lm.Libraries, k)
}
}
// This file is part of arduino-cli.
//
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
//
// This software is released under the GNU General Public License version 3,
// which covers the main part of arduino-cli.
// The terms of this license can be found at:
// https://www.gnu.org/licenses/gpl-3.0.en.html
//
// You can be released from the requirements of the above licenses by purchasing
// a commercial license. Buying such a license is mandatory if you want to
// modify or otherwise use the software for commercial activities involving the
// Arduino software without disclosing the source code of your own applications.
// To purchase a commercial license, send an email to license@arduino.cc.
package librariesmanager
import (
"testing"
"github.com/arduino/arduino-cli/arduino/libraries"
"github.com/arduino/go-paths-helper"
"github.com/stretchr/testify/require"
)
func Test_RescanLibrariesCallClear(t *testing.T) {
baseDir := paths.New(t.TempDir())
lm := NewLibraryManager(baseDir.Join("index_dir"), baseDir.Join("downloads_dir"))
lm.Libraries["testLibA"] = libraries.List{}
lm.Libraries["testLibB"] = libraries.List{}
lm.RescanLibraries()
require.Len(t, lm.Libraries, 0)
}
...@@ -382,3 +382,36 @@ func TestDaemonBundleLibInstall(t *testing.T) { ...@@ -382,3 +382,36 @@ func TestDaemonBundleLibInstall(t *testing.T) {
} }
} }
} }
func TestDaemonLibrariesRescanOnInstall(t *testing.T) {
/*
Ensures that the libraries are rescanned prior to installing a new one,
to avoid clashes with libraries installed after the daemon initialization.
To perform the check:
- the daemon is run and a gprc instance initialized
- a library is installed through the cli
- an attempt to install a new version of the library is done
with the gprc instance
The last attempt is expected to not raise an error
*/
env, cli := createEnvForDaemon(t)
defer env.CleanUp()
grpcInst := cli.Create()
require.NoError(t, grpcInst.Init("", "", func(ir *commands.InitResponse) {
fmt.Printf("INIT> %v\n", ir.GetMessage())
}))
cli.Run("lib", "install", "SD@1.2.3")
instCl, err := grpcInst.LibraryInstall(context.Background(), "SD", "1.2.4", false, false, true)
require.NoError(t, err)
for {
_, err := instCl.Recv()
if err == io.EOF {
break
}
require.NoError(t, err)
}
}
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