Commit 857caf2c authored by Cristian Maglie's avatar Cristian Maglie

Test if a library is already installed

Fix #111
parent 4234939e
......@@ -30,7 +30,6 @@
package librariesmanager
import (
"errors"
"fmt"
"os"
"path/filepath"
......@@ -43,35 +42,25 @@ import (
)
// Install installs a library and returns the installed path.
func Install(library *librariesindex.Release) (string, error) {
if library == nil {
return "", errors.New("Not existing version of the library")
}
/*
installedRelease, err := library.InstalledRelease()
if err != nil {
return err
}
if installedRelease != nil {
//if installedRelease.Version != library.Latest().Version {
err := removeRelease(library.Name, installedRelease)
if err != nil {
return err
func (lm *LibrariesManager) Install(indexLibrary *librariesindex.Release) (string, error) {
if installedLibs, have := lm.Libraries[indexLibrary.Library.Name]; have {
for _, installedLib := range installedLibs.Alternatives {
if installedLib.Location != libraries.Sketchbook {
continue
}
if installedLib.Version == indexLibrary.Version {
return installedLib.Folder.String(), fmt.Errorf("%s is already installed", indexLibrary.String())
}
//} else {
// return nil // Already installed and latest version.
//}
}
*/
}
libsFolder, err := configs.LibrariesFolder.Get()
if err != nil {
return "", fmt.Errorf("getting libraries directory: %s", err)
}
libPath := filepath.Join(libsFolder, utils.SanitizeName(library.Library.Name))
return libPath, library.Resource.Install(libsFolder, libPath)
libPath := filepath.Join(libsFolder, utils.SanitizeName(indexLibrary.Library.Name))
return libPath, indexLibrary.Resource.Install(libsFolder, libPath)
}
func removeRelease(libName string, r *libraries.Library) error {
......
......@@ -186,6 +186,11 @@ func TestLibDownloadAndInstall(t *testing.T) {
exitCode, d = executeWithArgs(t, "lib", "list")
require.Zero(t, exitCode, "exit code")
require.Contains(t, string(d), "Audio")
exitCode, d = executeWithArgs(t, "lib", "install", "Audio")
require.NotZero(t, exitCode, "exit code")
require.Contains(t, string(d), "Audio@")
require.Contains(t, string(d), "already installed")
}
func updateCoreIndex(t *testing.T) {
......
......@@ -75,11 +75,9 @@ func installLibraries(lm *librariesmanager.LibrariesManager, refs []*librariesin
}
for _, libRelease := range libReleasesToInstall {
// FIXME: the library is installed again even if it's already installed
logrus.WithField("library", libRelease).Info("Installing library")
if _, err := librariesmanager.Install(libRelease); err != nil {
if _, err := lm.Install(libRelease); err != nil {
logrus.WithError(err).Warn("Error installing library ", libRelease)
formatter.PrintError(err, "Error installing library: "+libRelease.String())
os.Exit(commands.ErrGeneric)
......
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