Skip to content

Commit ed7e96f

Browse files
committed
Fix installation of builtin tools
1 parent 6633d28 commit ed7e96f

File tree

1 file changed

+44
-11
lines changed

1 file changed

+44
-11
lines changed

commands/instances.go

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,17 @@ func Init(req *rpc.InitRequest) (<-chan *rpc.InitResponse, *status.Status) {
216216
}
217217
}
218218

219+
// We load hardware before verifying builtin tools are installed
220+
// otherwise we wouldn't find them and reinstall them each time
221+
// and they would never get reloaded.
222+
for _, err := range instance.PackageManager.LoadHardware() {
223+
outChan <- &rpc.InitResponse{
224+
Message: &rpc.InitResponse_Error{
225+
Error: err.Proto(),
226+
},
227+
}
228+
}
229+
219230
taskCallback := func(msg *rpc.TaskProgress) {
220231
outChan <- &rpc.InitResponse{
221232
Message: &rpc.InitResponse_InitProgress{
@@ -237,9 +248,19 @@ func Init(req *rpc.InitRequest) (<-chan *rpc.InitResponse, *status.Status) {
237248
}
238249

239250
// Install tools if necessary
240-
ctagsTool, _ := getBuiltinCtagsTool(instance.PackageManager)
241-
if ctagsTool == nil {
242-
if _, err := instance.installToolIfMissing(ctagsTool, downloadCallback, taskCallback); err != nil {
251+
toolHasBeenInstalled := false
252+
ctagsTool, err := getBuiltinCtagsTool(instance.PackageManager)
253+
if err != nil {
254+
s := status.Newf(codes.Internal, err.Error())
255+
outChan <- &rpc.InitResponse{
256+
Message: &rpc.InitResponse_Error{
257+
Error: s.Proto(),
258+
},
259+
}
260+
} else {
261+
ctagsInstalled, err := instance.installToolIfMissing(ctagsTool, downloadCallback, taskCallback)
262+
toolHasBeenInstalled = toolHasBeenInstalled || ctagsInstalled
263+
if err != nil {
243264
s := status.Newf(codes.Internal, err.Error())
244265
outChan <- &rpc.InitResponse{
245266
Message: &rpc.InitResponse_Error{
@@ -250,8 +271,17 @@ func Init(req *rpc.InitRequest) (<-chan *rpc.InitResponse, *status.Status) {
250271
}
251272

252273
serialDiscoveryTool, _ := getBuiltinSerialDiscoveryTool(instance.PackageManager)
253-
if serialDiscoveryTool == nil {
254-
if _, err := instance.installToolIfMissing(serialDiscoveryTool, downloadCallback, taskCallback); err != nil {
274+
if err != nil {
275+
s := status.Newf(codes.Internal, err.Error())
276+
outChan <- &rpc.InitResponse{
277+
Message: &rpc.InitResponse_Error{
278+
Error: s.Proto(),
279+
},
280+
}
281+
} else {
282+
serialDiscoveryToolInstalled, err := instance.installToolIfMissing(serialDiscoveryTool, downloadCallback, taskCallback)
283+
toolHasBeenInstalled = toolHasBeenInstalled || serialDiscoveryToolInstalled
284+
if err != nil {
255285
s := status.Newf(codes.Internal, err.Error())
256286
outChan <- &rpc.InitResponse{
257287
Message: &rpc.InitResponse_Error{
@@ -261,12 +291,15 @@ func Init(req *rpc.InitRequest) (<-chan *rpc.InitResponse, *status.Status) {
261291
}
262292
}
263293

264-
// Load hardware only after tools have been installed
265-
for _, err := range instance.PackageManager.LoadHardware() {
266-
outChan <- &rpc.InitResponse{
267-
Message: &rpc.InitResponse_Error{
268-
Error: err.Proto(),
269-
},
294+
if toolHasBeenInstalled {
295+
// We installed at least one new tool after loading hardware
296+
// so we must reload again otherwise we would never found them.
297+
for _, err := range instance.PackageManager.LoadHardware() {
298+
outChan <- &rpc.InitResponse{
299+
Message: &rpc.InitResponse_Error{
300+
Error: err.Proto(),
301+
},
302+
}
270303
}
271304
}
272305

0 commit comments

Comments
 (0)