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