Skip to content

Commit cfcf23f

Browse files
author
rsora
committed
Fixes ext bug
1 parent 3315f0c commit cfcf23f

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

Diff for: commands/upload/upload.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -157,29 +157,26 @@ func Upload(ctx context.Context, req *rpc.UploadReq, outStream io.Writer, errStr
157157
// Start smart fetch process for the built sketch
158158
var uploadPaths []*paths.Path
159159

160-
// Search for built sketch to upload in CLI param importFile (if passed)...
161-
// ...or in the Export path (the Sketch Path)
162-
163160
// Set path to compiled binary
164161
// Make the filename without the FQBN configs part
165162
fqbn.Configs = properties.NewMap()
166163
fqbnSuffix := strings.Replace(fqbn.String(), ":", ".", -1)
167164

168165
var importPath *paths.Path
169166
var importFile string
170-
// If no importFile is passed, use sketch path
171167
if req.GetImportFile() == "" {
168+
// Search for built sketch to upload in CLI param importFile (if passed)...
172169
importPath = sketch.FullPath
173170
importFile = sketch.Name + "." + fqbnSuffix
174171
} else {
172+
// ...or in the Export path (the Sketch Path)
175173
importPath = paths.New(req.GetImportFile()).Parent()
176174
importFile = paths.New(req.GetImportFile()).Base()
177175
}
178176

179177
// Remove file extension if any from input
180-
importFileExt := paths.New(importFile).Ext()
181-
if strings.HasSuffix(importFile, importFileExt) {
182-
importFile = importFile[:len(importFile)-len(importFileExt)]
178+
if strings.HasSuffix(importFile, ext) {
179+
importFile = importFile[:len(importFile)-len(ext)]
183180
}
184181

185182
uploadPaths = append(uploadPaths, importPath.Join(importFile+ext))
@@ -195,13 +192,14 @@ func Upload(ctx context.Context, req *rpc.UploadReq, outStream io.Writer, errStr
195192
fallbackBuildPath := builder.GenBuildPath(sketchPath)
196193
// If we search inside the build.path, compile artifact do not have the fqbnSuffix in the filename
197194
uploadPaths = append(uploadPaths, fallbackBuildPath.Join(sketch.Name+".ino"+ext))
195+
198196
for _, p := range uploadPaths {
199197
if _, err := p.Stat(); err == nil {
200198
uploadProperties.SetPath("build.path", p.Parent())
201199
name := p.Base()
202200
name = name[:len(name)-len(ext)]
203201
uploadProperties.Set("build.project_name", name)
204-
202+
break
205203
} else {
206204
logrus.Warnf("Built sketch opening error in %s: %s", p, err)
207205
}
@@ -305,14 +303,16 @@ func getExtensionFromRecipe(uploadProperties *properties.Map, err error) (string
305303
for _, t := range cmdArgs {
306304
if strings.Contains(t, "build.project_name") {
307305
uploadInputPath = paths.New(t)
306+
break
308307
}
309308
}
310309

311310
if uploadInputPath == nil {
312311
return "", fmt.Errorf("cannot find upload file extension in upload recipe")
313312
}
314-
315-
return uploadInputPath.Ext(), nil
313+
// trim extension from "}" and following recipe tokens as they could be erroneously included by the Ext() func
314+
trimmedExt := strings.Split(uploadInputPath.Ext(), "}")[0]
315+
return trimmedExt, nil
316316
}
317317

318318
func touchSerialPortAt1200bps(port string) error {

0 commit comments

Comments
 (0)