@@ -17,6 +17,7 @@ package core
1717
1818import (
1919 "context"
20+ "fmt"
2021
2122 "github.com/arduino/arduino-cli/arduino"
2223 "github.com/arduino/arduino-cli/arduino/cores"
@@ -44,37 +45,43 @@ func PlatformInstall(ctx context.Context, req *rpc.PlatformInstallRequest,
4445 PlatformArchitecture : req .Architecture ,
4546 PlatformVersion : version ,
4647 }
47- platform , tools , err := pm .FindPlatformReleaseDependencies (ref )
48+ platformRelease , tools , err := pm .FindPlatformReleaseDependencies (ref )
4849 if err != nil {
4950 return nil , & arduino.PlatformNotFoundError {Platform : ref .String (), Cause : err }
5051 }
5152
52- didInstall , err := installPlatform (pm , platform , tools , downloadCB , taskCB , req .GetSkipPostInstall ())
53- if err != nil {
54- return nil , err
53+ // Prerequisite checks before install
54+ if platformRelease .IsInstalled () {
55+ taskCB (& rpc.TaskProgress {Name : tr ("Platform %s already installed" , platformRelease ), Completed : true })
56+ return & rpc.PlatformInstallResponse {}, nil
5557 }
5658
57- if didInstall {
58- if err := commands .Init (& rpc.InitRequest {Instance : req .Instance }, nil ); err != nil {
59- return nil , err
59+ if req .GetNoOverwrite () {
60+ if installed := pm .GetInstalledPlatformRelease (platformRelease .Platform ); installed != nil {
61+ return nil , fmt .Errorf ("%s: %s" ,
62+ tr ("Platform %s already installed" , installed ),
63+ tr ("could not overwrite" ))
6064 }
6165 }
6266
67+ if err := installPlatform (pm , platformRelease , tools , downloadCB , taskCB , req .GetSkipPostInstall ()); err != nil {
68+ return nil , err
69+ }
70+
71+ if err := commands .Init (& rpc.InitRequest {Instance : req .Instance }, nil ); err != nil {
72+ return nil , err
73+ }
74+
6375 return & rpc.PlatformInstallResponse {}, nil
6476}
6577
6678func installPlatform (pm * packagemanager.PackageManager ,
6779 platformRelease * cores.PlatformRelease , requiredTools []* cores.ToolRelease ,
6880 downloadCB rpc.DownloadProgressCB , taskCB rpc.TaskProgressCB ,
69- skipPostInstall bool ) ( bool , error ) {
81+ skipPostInstall bool ) error {
7082 log := pm .Log .WithField ("platform" , platformRelease )
7183
7284 // Prerequisite checks before install
73- if platformRelease .IsInstalled () {
74- log .Warn ("Platform already installed" )
75- taskCB (& rpc.TaskProgress {Name : tr ("Platform %s already installed" , platformRelease ), Completed : true })
76- return false , nil
77- }
7885 toolsToInstall := []* cores.ToolRelease {}
7986 for _ , tool := range requiredTools {
8087 if tool .IsInstalled () {
@@ -89,18 +96,18 @@ func installPlatform(pm *packagemanager.PackageManager,
8996 taskCB (& rpc.TaskProgress {Name : tr ("Downloading packages" )})
9097 for _ , tool := range toolsToInstall {
9198 if err := downloadTool (pm , tool , downloadCB ); err != nil {
92- return false , err
99+ return err
93100 }
94101 }
95102 if err := downloadPlatform (pm , platformRelease , downloadCB ); err != nil {
96- return false , err
103+ return err
97104 }
98105 taskCB (& rpc.TaskProgress {Completed : true })
99106
100107 // Install tools first
101108 for _ , tool := range toolsToInstall {
102109 if err := commands .InstallToolRelease (pm , tool , taskCB ); err != nil {
103- return false , err
110+ return err
104111 }
105112 }
106113
@@ -112,8 +119,8 @@ func installPlatform(pm *packagemanager.PackageManager,
112119 taskCB (& rpc.TaskProgress {Name : tr ("Installing platform %s" , platformRelease )})
113120 } else {
114121 // A platform with a different version is already installed
115- log .Info ("Upgrading platform " + installed .String ())
116- taskCB (& rpc.TaskProgress {Name : tr ("Upgrading platform %[1]s with %[2]s" , installed , platformRelease )})
122+ log .Info ("Replacing platform " + installed .String ())
123+ taskCB (& rpc.TaskProgress {Name : tr ("Replacing platform %[1]s with %[2]s" , installed , platformRelease )})
117124 platformRef := & packagemanager.PlatformReference {
118125 Package : platformRelease .Platform .Package .Name ,
119126 PlatformArchitecture : platformRelease .Platform .Architecture ,
@@ -126,14 +133,14 @@ func installPlatform(pm *packagemanager.PackageManager,
126133 var err error
127134 _ , installedTools , err = pm .FindPlatformReleaseDependencies (platformRef )
128135 if err != nil {
129- return false , & arduino.NotFoundError {Message : tr ("Can't find dependencies for platform %s" , platformRef ), Cause : err }
136+ return & arduino.NotFoundError {Message : tr ("Can't find dependencies for platform %s" , platformRef ), Cause : err }
130137 }
131138 }
132139
133140 // Install
134141 if err := pm .InstallPlatform (platformRelease ); err != nil {
135142 log .WithError (err ).Error ("Cannot install platform" )
136- return false , & arduino.FailedInstallError {Message : tr ("Cannot install platform" ), Cause : err }
143+ return & arduino.FailedInstallError {Message : tr ("Cannot install platform" ), Cause : err }
137144 }
138145
139146 // If upgrading remove previous release
@@ -151,7 +158,7 @@ func installPlatform(pm *packagemanager.PackageManager,
151158 taskCB (& rpc.TaskProgress {Message : tr ("Error rolling-back changes: %s" , err )})
152159 }
153160
154- return false , & arduino.FailedInstallError {Message : tr ("Cannot upgrade platform" ), Cause : uninstallErr }
161+ return & arduino.FailedInstallError {Message : tr ("Cannot upgrade platform" ), Cause : uninstallErr }
155162 }
156163
157164 // Uninstall unused tools
@@ -177,5 +184,5 @@ func installPlatform(pm *packagemanager.PackageManager,
177184
178185 log .Info ("Platform installed" )
179186 taskCB (& rpc.TaskProgress {Message : tr ("Platform %s installed" , platformRelease ), Completed : true })
180- return true , nil
187+ return nil
181188}
0 commit comments