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