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