Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
test: rescan libraries before install
  • Loading branch information
Luca Bianconi committed Jan 18, 2023
commit 6e5a811de1981c79b3eddeb10043458c74744503
14 changes: 7 additions & 7 deletions arduino/libraries/librariesmanager/librariesmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,9 @@ func (lm *LibrariesManager) AddPlatformReleaseLibrariesDir(plaftormRelease *core
})
}

func (lm *LibrariesManager) ClearLibraries() {
for k := range lm.Libraries {
delete(lm.Libraries, k)
}
}

// RescanLibraries reload all installed libraries in the system.
func (lm *LibrariesManager) RescanLibraries() []*status.Status {
lm.ClearLibraries()
lm.clearLibraries()
statuses := []*status.Status{}
for _, dir := range lm.LibrariesDir {
if errs := lm.LoadLibrariesFromDir(dir); len(errs) > 0 {
Expand Down Expand Up @@ -224,3 +218,9 @@ func (lm *LibrariesManager) FindByReference(libRef *librariesindex.Reference, in
}
return alternatives.FilterByVersionAndInstallLocation(libRef.Version, installLocation)
}

func (lm *LibrariesManager) clearLibraries() {
for k := range lm.Libraries {
delete(lm.Libraries, k)
}
}
14 changes: 14 additions & 0 deletions arduino/libraries/librariesmanager/librariesmanager_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// 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 (
Expand Down
33 changes: 33 additions & 0 deletions internal/integrationtest/daemon/daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

}