Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a58d5ad

Browse files
authored
fix: scan libraries on install (#2037)
1 parent 1897368 commit a58d5ad

File tree

4 files changed

+73
-0
lines changed

4 files changed

+73
-0
lines changed

‎arduino/libraries/librariesmanager/install.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ func (lm *LibrariesManager) InstallPrerequisiteCheck(name string, version *semve
6464
return nil, err
6565
}
6666

67+
lm.RescanLibraries()
6768
libs := lm.FindByReference(&librariesindex.Reference{Name: name}, installLocation)
6869

6970
if len(libs) > 1 {

‎arduino/libraries/librariesmanager/librariesmanager.go‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ func (lm *LibrariesManager) AddPlatformReleaseLibrariesDir(plaftormRelease *core
132132

133133
// RescanLibraries reload all installed libraries in the system.
134134
func (lm *LibrariesManager) RescanLibraries() []*status.Status {
135+
lm.clearLibraries()
135136
statuses := []*status.Status{}
136137
for _, dir := range lm.LibrariesDir {
137138
if errs := lm.LoadLibrariesFromDir(dir); len(errs) > 0 {
@@ -217,3 +218,9 @@ func (lm *LibrariesManager) FindByReference(libRef *librariesindex.Reference, in
217218
}
218219
return alternatives.FilterByVersionAndInstallLocation(libRef.Version, installLocation)
219220
}
221+
222+
func (lm *LibrariesManager) clearLibraries() {
223+
for k := range lm.Libraries {
224+
delete(lm.Libraries, k)
225+
}
226+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to license@arduino.cc.
15+
package librariesmanager
16+
17+
import (
18+
"testing"
19+
20+
"github.com/arduino/arduino-cli/arduino/libraries"
21+
"github.com/arduino/go-paths-helper"
22+
"github.com/stretchr/testify/require"
23+
)
24+
25+
func Test_RescanLibrariesCallClear(t *testing.T) {
26+
baseDir := paths.New(t.TempDir())
27+
lm := NewLibraryManager(baseDir.Join("index_dir"), baseDir.Join("downloads_dir"))
28+
lm.Libraries["testLibA"] = libraries.List{}
29+
lm.Libraries["testLibB"] = libraries.List{}
30+
lm.RescanLibraries()
31+
require.Len(t, lm.Libraries, 0)
32+
}

‎internal/integrationtest/daemon/daemon_test.go‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,3 +382,36 @@ func TestDaemonBundleLibInstall(t *testing.T) {
382382
}
383383
}
384384
}
385+
386+
func TestDaemonLibrariesRescanOnInstall(t *testing.T) {
387+
/*
388+
Ensures that the libraries are rescanned prior to installing a new one,
389+
to avoid clashes with libraries installed after the daemon initialization.
390+
To perform the check:
391+
- the daemon is run and a gprc instance initialized
392+
- a library is installed through the cli
393+
- an attempt to install a new version of the library is done
394+
with the gprc instance
395+
The last attempt is expected to not raise an error
396+
*/
397+
env, cli := createEnvForDaemon(t)
398+
defer env.CleanUp()
399+
400+
grpcInst := cli.Create()
401+
require.NoError(t, grpcInst.Init("", "", func(ir *commands.InitResponse) {
402+
fmt.Printf("INIT> %v\n", ir.GetMessage())
403+
}))
404+
cli.Run("lib", "install", "SD@1.2.3")
405+
406+
instCl, err := grpcInst.LibraryInstall(context.Background(), "SD", "1.2.4", false, false, true)
407+
408+
require.NoError(t, err)
409+
for {
410+
_, err := instCl.Recv()
411+
if err == io.EOF {
412+
break
413+
}
414+
require.NoError(t, err)
415+
}
416+
417+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /