Skip to content

Commit 525980c

Browse files
committed
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.
1 parent 2d5ec7f commit 525980c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Diff for: commands/upload/upload.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ func UsingProgrammer(ctx context.Context, req *rpc.UploadUsingProgrammerRequest,
201201
func runProgramAction(pme *packagemanager.Explorer,
202202
sk *sketch.Sketch,
203203
watch <-chan *rpc.BoardListWatchResponse,
204-
importFile, importDir, fqbnIn string, port *rpc.Port,
204+
importFile, importDir, fqbnIn string, userPort *rpc.Port,
205205
programmerID string,
206206
verbose, verify, burnBootloader bool,
207207
outStream, errStream io.Writer,
@@ -212,6 +212,7 @@ func runProgramAction(pme *packagemanager.Explorer,
212212
go f.DiscardCh(watch)
213213
}()
214214

215+
port := userPort
215216
if port == nil || (port.Address == "" && port.Protocol == "") {
216217
// For no-port uploads use "default" protocol
217218
port = &rpc.Port{Protocol: "default"}
@@ -519,7 +520,11 @@ func runProgramAction(pme *packagemanager.Explorer,
519520
uploadCompleted()
520521
logrus.Tracef("Upload successful")
521522

522-
return updatedUploadPort.Await(), nil
523+
updatedPort := updatedUploadPort.Await()
524+
if updatedPort == nil {
525+
updatedPort = userPort
526+
}
527+
return userPort, nil
523528
}
524529

525530
func detectUploadPort(uploadCtx context.Context, uploadPort *rpc.Port, watch <-chan *rpc.BoardListWatchResponse, result f.Future[*rpc.Port]) {

0 commit comments

Comments
 (0)