Skip to content

Commit 05f0d49

Browse files
committed
Check if libraries needs to be installed prior to download/install
1 parent 35834c5 commit 05f0d49

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

commands/lib/install.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,25 @@ func LibraryInstall(ctx context.Context, req *rpc.LibraryInstallRequest, downloa
7878
libReleasesToInstall = append(libReleasesToInstall, libRelease)
7979
}
8080

81-
// Check if any of the libraries to install is already installed
82-
if req.GetNoOverwrite() {
83-
for _, libRelease := range libReleasesToInstall {
84-
_, libReplaced, err := lm.InstallPrerequisiteCheck(libRelease)
85-
if err != nil {
86-
return err
87-
}
81+
// Check if any of the libraries to install is already installed and remove it from the list
82+
j := 0
83+
for i, libRelease := range libReleasesToInstall {
84+
_, libReplaced, err := lm.InstallPrerequisiteCheck(libRelease)
85+
if errors.Is(err, librariesmanager.ErrAlreadyInstalled) {
86+
taskCB(&rpc.TaskProgress{Message: tr("Already installed %s", libRelease), Completed: true})
87+
} else if err != nil {
88+
return err
89+
} else {
90+
libReleasesToInstall[j] = libReleasesToInstall[i]
91+
j++
92+
}
93+
if req.GetNoOverwrite() {
8894
if libReplaced != nil {
8995
return fmt.Errorf(tr("Library %[1]s is already installed, but with a different version: %[2]s", libRelease, libReplaced))
9096
}
9197
}
9298
}
99+
libReleasesToInstall = libReleasesToInstall[:j]
93100

94101
didInstall := false
95102
for _, libRelease := range libReleasesToInstall {

test/test_lib.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,13 @@ def test_install_library_with_dependencies(run_command):
251251
assert res.failed
252252
assert run_command(["lib", "install", "MD_Parola@3.6.1"])
253253

254+
# Test --no-overwrite with transitive dependencies
255+
assert run_command(["lib", "install", "SD"])
256+
assert run_command(["lib", "install", "Arduino_Builtin", "--no-overwrite"])
257+
assert run_command(["lib", "install", "SD@1.2.3"])
258+
res = run_command(["lib", "install", "Arduino_Builtin", "--no-overwrite"])
259+
assert res.failed
260+
254261

255262
def test_install_no_deps(run_command):
256263
assert run_command(["update"])

0 commit comments

Comments
 (0)