Skip to content

Added no_overwrite flag in LibraryInstall #1793

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
21 changes: 12 additions & 9 deletions cli/lib/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ import (
)

var (
noDeps bool
gitURL bool
zipPath bool
noDeps bool
noOverwrite bool
gitURL bool
zipPath bool
)

func initInstallCommand() *cobra.Command {
Expand All @@ -59,6 +60,7 @@ func initInstallCommand() *cobra.Command {
},
}
installCommand.Flags().BoolVar(&noDeps, "no-deps", false, tr("Do not install dependencies."))
installCommand.Flags().BoolVar(&noOverwrite, "no-overwrite", false, tr("Do not overwrite already installed libraries."))
installCommand.Flags().BoolVar(&gitURL, "git-url", false, tr("Enter git url for libraries hosted on repositories"))
installCommand.Flags().BoolVar(&zipPath, "zip-path", false, tr("Enter a path to zip file"))
return installCommand
Expand Down Expand Up @@ -87,7 +89,7 @@ func runInstallCommand(cmd *cobra.Command, args []string) {
err := lib.ZipLibraryInstall(context.Background(), &rpc.ZipLibraryInstallRequest{
Instance: instance,
Path: path,
Overwrite: true,
Overwrite: !noOverwrite,
}, output.TaskProgress())
if err != nil {
feedback.Errorf(tr("Error installing Zip Library: %v"), err)
Expand All @@ -110,7 +112,7 @@ func runInstallCommand(cmd *cobra.Command, args []string) {
err := lib.GitLibraryInstall(context.Background(), &rpc.GitLibraryInstallRequest{
Instance: instance,
Url: url,
Overwrite: true,
Overwrite: !noOverwrite,
}, output.TaskProgress())
if err != nil {
feedback.Errorf(tr("Error installing Git Library: %v"), err)
Expand All @@ -128,10 +130,11 @@ func runInstallCommand(cmd *cobra.Command, args []string) {

for _, libRef := range libRefs {
libraryInstallRequest := &rpc.LibraryInstallRequest{
Instance: instance,
Name: libRef.Name,
Version: libRef.Version,
NoDeps: noDeps,
Instance: instance,
Name: libRef.Name,
Version: libRef.Version,
NoDeps: noDeps,
NoOverwrite: noOverwrite,
}
err := lib.LibraryInstall(context.Background(), libraryInstallRequest, output.ProgressBar(), output.TaskProgress())
if err != nil {
Expand Down
28 changes: 27 additions & 1 deletion commands/lib/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package lib
import (
"context"
"errors"
"fmt"

"github.com/arduino/arduino-cli/arduino"
"github.com/arduino/arduino-cli/arduino/libraries/librariesindex"
Expand Down Expand Up @@ -64,7 +65,8 @@ func LibraryInstall(ctx context.Context, req *rpc.LibraryInstallRequest, downloa
}
}

didInstall := false
// Find the libReleasesToInstall to install
libReleasesToInstall := []*librariesindex.Release{}
for _, lib := range toInstall {
libRelease, err := findLibraryIndexRelease(lm, &rpc.LibraryInstallRequest{
Name: lib.Name,
Expand All @@ -73,7 +75,31 @@ func LibraryInstall(ctx context.Context, req *rpc.LibraryInstallRequest, downloa
if err != nil {
return err
}
libReleasesToInstall = append(libReleasesToInstall, libRelease)
}

// Check if any of the libraries to install is already installed and remove it from the list
j := 0
for i, libRelease := range libReleasesToInstall {
_, libReplaced, err := lm.InstallPrerequisiteCheck(libRelease)
if errors.Is(err, librariesmanager.ErrAlreadyInstalled) {
taskCB(&rpc.TaskProgress{Message: tr("Already installed %s", libRelease), Completed: true})
} else if err != nil {
return err
} else {
libReleasesToInstall[j] = libReleasesToInstall[i]
j++
}
if req.GetNoOverwrite() {
if libReplaced != nil {
return fmt.Errorf(tr("Library %[1]s is already installed, but with a different version: %[2]s", libRelease, libReplaced))
}
}
}
libReleasesToInstall = libReleasesToInstall[:j]

didInstall := false
for _, libRelease := range libReleasesToInstall {
if err := downloadLibrary(lm, libRelease, downloadCB, taskCB); err != nil {
return err
}
Expand Down
Loading