From 5896fba900db441a1a3a2a3af30536c0d8cb3425 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 9 Aug 2023 14:31:39 +0200 Subject: [PATCH] Always return an updatedUploadPort. Arduino CLI should always return the port after an upload, even in the case where no port change is expected. The consumer shouldn't be required to implement "if not updated_upload_port, use original port" logic. The whole point is that all the logic for determining which port should be selected after an upload should be implemented in Arduino CLI. The consumer should be able to simply select the port Arduino CLI tells it to select in all cases. --- commands/upload/upload.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/commands/upload/upload.go b/commands/upload/upload.go index b0dedee0c42..227166d07c8 100644 --- a/commands/upload/upload.go +++ b/commands/upload/upload.go @@ -201,7 +201,7 @@ func UsingProgrammer(ctx context.Context, req *rpc.UploadUsingProgrammerRequest, func runProgramAction(pme *packagemanager.Explorer, sk *sketch.Sketch, watch <-chan *rpc.BoardListWatchResponse, - importFile, importDir, fqbnIn string, port *rpc.Port, + importFile, importDir, fqbnIn string, userPort *rpc.Port, programmerID string, verbose, verify, burnBootloader bool, outStream, errStream io.Writer, @@ -212,6 +212,7 @@ func runProgramAction(pme *packagemanager.Explorer, go f.DiscardCh(watch) }() + port := userPort if port == nil || (port.Address == "" && port.Protocol == "") { // For no-port uploads use "default" protocol port = &rpc.Port{Protocol: "default"} @@ -519,7 +520,11 @@ func runProgramAction(pme *packagemanager.Explorer, uploadCompleted() logrus.Tracef("Upload successful") - return updatedUploadPort.Await(), nil + updatedPort := updatedUploadPort.Await() + if updatedPort == nil { + updatedPort = userPort + } + return userPort, nil } func detectUploadPort(uploadCtx context.Context, uploadPort *rpc.Port, watch <-chan *rpc.BoardListWatchResponse, result f.Future[*rpc.Port]) {