Commit eb0f5d53 authored by Cristian Maglie's avatar Cristian Maglie

Improved core install/uninstall precodition checks

parent 3dcd1ca4
......@@ -214,6 +214,11 @@ func (release *PlatformRelease) GetLibrariesDir() *paths.Path {
return nil
}
// IsInstalled returns true if the PlatformRelease is installed
func (release *PlatformRelease) IsInstalled() bool {
return release.InstallDir != nil
}
func (release *PlatformRelease) String() string {
version := ""
if release.Version != nil {
......
......@@ -60,31 +60,30 @@ func downloadPlatformByRef(pm *packagemanager.PackageManager, platformsRef *pack
formatter.PrintError(err, "Could not determine platform dependencies")
os.Exit(commands.ErrBadCall)
}
// Check if all tools have a flavor available for the current OS
downloadPlatform(pm, platform)
for _, tool := range tools {
downloadTool(pm, tool)
}
}
func downloadPlatform(pm *packagemanager.PackageManager, platformRelease *cores.PlatformRelease) {
// Download platform
resp, err := pm.DownloadPlatformRelease(platformRelease)
download(resp, err, platformRelease.String())
}
func downloadTool(pm *packagemanager.PackageManager, tool *cores.ToolRelease) {
// Check if tool has a flavor available for the current OS
if tool.GetCompatibleFlavour() == nil {
formatter.PrintErrorMessage("The tool " + tool.String() + " is not available for the current OS")
os.Exit(commands.ErrGeneric)
}
}
// Download tools
for _, tool := range tools {
DownloadToolRelease(pm, tool)
}
// Download cores
formatter.Print("Downloading " + platform.String() + "...")
resp, err := pm.DownloadPlatformRelease(platform)
download(resp, err, platform.String())
logrus.Info("Done")
}
// DownloadToolRelease downloads a ToolRelease
func DownloadToolRelease(pm *packagemanager.PackageManager, toolRelease *cores.ToolRelease) {
formatter.Print("Downloading " + toolRelease.String() + "...")
resp, err := pm.DownloadToolRelease(toolRelease)
download(resp, err, toolRelease.String())
}
......@@ -98,6 +97,7 @@ func download(d *downloader.Downloader, err error, label string) {
formatter.Print(label + " already downloaded")
return
}
formatter.Print("Downloading " + label + "...")
formatter.DownloadProgressBar(d, label)
if d.Error() != nil {
formatter.PrintError(d.Error(), "Error downloading "+label)
......
......@@ -50,7 +50,6 @@ func runInstallCommand(cmd *cobra.Command, args []string) {
pm := commands.InitPackageManagerWithoutBundles()
for _, platformRef := range platformsRefs {
downloadPlatformByRef(pm, platformRef)
installPlatformByRef(pm, platformRef)
}
......@@ -64,19 +63,39 @@ func installPlatformByRef(pm *packagemanager.PackageManager, platformRef *packag
os.Exit(commands.ErrBadCall)
}
// TODO: Check install prerequisites here
installPlatform(pm, platform, tools)
}
// TODO: Download here
func installPlatform(pm *packagemanager.PackageManager, platformRelease *cores.PlatformRelease, requiredTools []*cores.ToolRelease) {
log := pm.Log.WithField("platform", platformRelease)
for _, tool := range tools {
InstallToolRelease(pm, tool)
// Prerequisite checks before install
if platformRelease.IsInstalled() {
log.Warn("Platform already installed")
formatter.Print("Platform " + platformRelease.String() + " already installed")
return
}
toolsToInstall := []*cores.ToolRelease{}
for _, tool := range requiredTools {
if tool.IsInstalled() {
log.WithField("tool", tool).Warn("Tool already installed")
formatter.Print("Tool " + tool.String() + " already installed")
} else {
toolsToInstall = append(toolsToInstall, tool)
}
}
installPlatformRelease(pm, platform)
}
func installPlatformRelease(pm *packagemanager.PackageManager, platformRelease *cores.PlatformRelease) {
log := pm.Log.WithField("platform", platformRelease)
// Package download
for _, tool := range toolsToInstall {
downloadTool(pm, tool)
}
downloadPlatform(pm, platformRelease)
for _, tool := range toolsToInstall {
InstallToolRelease(pm, tool)
}
// Are we installing or upgrading?
platform := platformRelease.Platform
installed := pm.GetInstalledPlatformRelease(platform)
if installed == nil {
......@@ -87,12 +106,8 @@ func installPlatformRelease(pm *packagemanager.PackageManager, platformRelease *
formatter.Print("Updating " + installed.String() + " with " + platformRelease.String() + "...")
}
// Install
err := pm.InstallPlatform(platformRelease)
if os.IsExist(err) {
log.Warn("Platform already installed")
formatter.Print("Platform " + platformRelease.String() + " already installed")
return
}
if err != nil {
log.WithError(err).Error("Cannot install platform")
formatter.PrintError(err, "Cannot install platform")
......@@ -125,15 +140,15 @@ func installPlatformRelease(pm *packagemanager.PackageManager, platformRelease *
func InstallToolRelease(pm *packagemanager.PackageManager, toolRelease *cores.ToolRelease) {
log := pm.Log.WithField("Tool", toolRelease)
log.Info("Installing tool")
formatter.Print("Installing " + toolRelease.String())
err := pm.InstallTool(toolRelease)
if os.IsExist(err) {
if toolRelease.IsInstalled() {
log.Warn("Tool already installed")
formatter.Print("Tool " + toolRelease.String() + " already installed")
return
}
log.Info("Installing tool")
formatter.Print("Installing " + toolRelease.String() + "...")
err := pm.InstallTool(toolRelease)
if err != nil {
log.WithError(err).Warn("Cannot install tool")
formatter.PrintError(err, "Cannot install tool: "+toolRelease.String())
......
......@@ -103,7 +103,7 @@ func uninstallToolRelease(pm *packagemanager.PackageManager, toolRelease *cores.
log := pm.Log.WithField("Tool", toolRelease)
log.Info("Uninstalling tool")
formatter.Print("Uninstalling " + toolRelease.String())
formatter.Print("Uninstalling " + toolRelease.String() + "...")
if err := pm.UninstallTool(toolRelease); err != nil {
log.WithError(err).Error("Error uninstalling")
......
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