@@ -49,15 +49,18 @@ func PlatformInstall(ctx context.Context, req *rpc.PlatformInstallRequest,
49
49
return nil , & arduino.PlatformNotFoundError {Platform : ref .String (), Cause : err }
50
50
}
51
51
52
- didInstall , err := installPlatform (pm , platformRelease , tools , downloadCB , taskCB , req .GetSkipPostInstall ())
53
- if err != nil {
52
+ // Prerequisite checks before install
53
+ if platformRelease .IsInstalled () {
54
+ taskCB (& rpc.TaskProgress {Name : tr ("Platform %s already installed" , platformRelease ), Completed : true })
55
+ return & rpc.PlatformInstallResponse {}, nil
56
+ }
57
+
58
+ if err := installPlatform (pm , platformRelease , tools , downloadCB , taskCB , req .GetSkipPostInstall ()); err != nil {
54
59
return nil , err
55
60
}
56
61
57
- if didInstall {
58
- if err := commands .Init (& rpc.InitRequest {Instance : req .Instance }, nil ); err != nil {
59
- return nil , err
60
- }
62
+ if err := commands .Init (& rpc.InitRequest {Instance : req .Instance }, nil ); err != nil {
63
+ return nil , err
61
64
}
62
65
63
66
return & rpc.PlatformInstallResponse {}, nil
@@ -66,15 +69,10 @@ func PlatformInstall(ctx context.Context, req *rpc.PlatformInstallRequest,
66
69
func installPlatform (pm * packagemanager.PackageManager ,
67
70
platformRelease * cores.PlatformRelease , requiredTools []* cores.ToolRelease ,
68
71
downloadCB rpc.DownloadProgressCB , taskCB rpc.TaskProgressCB ,
69
- skipPostInstall bool ) ( bool , error ) {
72
+ skipPostInstall bool ) error {
70
73
log := pm .Log .WithField ("platform" , platformRelease )
71
74
72
75
// 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
- }
78
76
toolsToInstall := []* cores.ToolRelease {}
79
77
for _ , tool := range requiredTools {
80
78
if tool .IsInstalled () {
@@ -89,18 +87,18 @@ func installPlatform(pm *packagemanager.PackageManager,
89
87
taskCB (& rpc.TaskProgress {Name : tr ("Downloading packages" )})
90
88
for _ , tool := range toolsToInstall {
91
89
if err := downloadTool (pm , tool , downloadCB ); err != nil {
92
- return false , err
90
+ return err
93
91
}
94
92
}
95
93
if err := downloadPlatform (pm , platformRelease , downloadCB ); err != nil {
96
- return false , err
94
+ return err
97
95
}
98
96
taskCB (& rpc.TaskProgress {Completed : true })
99
97
100
98
// Install tools first
101
99
for _ , tool := range toolsToInstall {
102
100
if err := commands .InstallToolRelease (pm , tool , taskCB ); err != nil {
103
- return false , err
101
+ return err
104
102
}
105
103
}
106
104
@@ -126,14 +124,14 @@ func installPlatform(pm *packagemanager.PackageManager,
126
124
var err error
127
125
_ , installedTools , err = pm .FindPlatformReleaseDependencies (platformRef )
128
126
if err != nil {
129
- return false , & arduino.NotFoundError {Message : tr ("Can't find dependencies for platform %s" , platformRef ), Cause : err }
127
+ return & arduino.NotFoundError {Message : tr ("Can't find dependencies for platform %s" , platformRef ), Cause : err }
130
128
}
131
129
}
132
130
133
131
// Install
134
132
if err := pm .InstallPlatform (platformRelease ); err != nil {
135
133
log .WithError (err ).Error ("Cannot install platform" )
136
- return false , & arduino.FailedInstallError {Message : tr ("Cannot install platform" ), Cause : err }
134
+ return & arduino.FailedInstallError {Message : tr ("Cannot install platform" ), Cause : err }
137
135
}
138
136
139
137
// If upgrading remove previous release
@@ -151,7 +149,7 @@ func installPlatform(pm *packagemanager.PackageManager,
151
149
taskCB (& rpc.TaskProgress {Message : tr ("Error rolling-back changes: %s" , err )})
152
150
}
153
151
154
- return false , & arduino.FailedInstallError {Message : tr ("Cannot upgrade platform" ), Cause : uninstallErr }
152
+ return & arduino.FailedInstallError {Message : tr ("Cannot upgrade platform" ), Cause : uninstallErr }
155
153
}
156
154
157
155
// Uninstall unused tools
@@ -177,5 +175,5 @@ func installPlatform(pm *packagemanager.PackageManager,
177
175
178
176
log .Info ("Platform installed" )
179
177
taskCB (& rpc.TaskProgress {Message : tr ("Platform %s installed" , platformRelease ), Completed : true })
180
- return true , nil
178
+ return nil
181
179
}
0 commit comments