Skip to content

Commit c7855c1

Browse files
committed
Make --input-dir handle gracefully some rare cases
Using `--input-dir path/to/firmware` with a directory containing: path/to/firmware/firmware.ino.bin path/to/firmware/some_other_firmware_name.ino.bin should not fail but select `firmware.ino.bin` for upload because the containing folder has the same name. See arduino#765 (comment)
1 parent d56e8d4 commit c7855c1

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

Diff for: commands/upload/upload.go

+9
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,15 @@ func detectSketchNameFromBuildPath(buildPath *paths.Path) (string, error) {
438438
return "", err
439439
}
440440

441+
if absBuildPath, err := buildPath.Abs(); err == nil {
442+
candidateName := absBuildPath.Base() + ".ino"
443+
f := files.Clone()
444+
f.FilterPrefix(candidateName + ".")
445+
if f.Len() > 0 {
446+
return candidateName, nil
447+
}
448+
}
449+
441450
candidateName := ""
442451
var candidateFile *paths.Path
443452
for _, file := range files {

Diff for: commands/upload/upload_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ func TestDetermineBuildPathAndSketchName(t *testing.T) {
9797
{"", "testdata/build_path_2", blonk, fqbn, "testdata/build_path_2", "Blink.ino"},
9898
// 15: error: used both importPath and importFile
9999
{"testdata/build_path_2/Blink.ino.hex", "testdata/build_path_2", blonk, fqbn, "<nil>", ""},
100+
101+
// 16: importPath containing multiple firmwares, but one has the same name as the containing folder
102+
{"", "testdata/firmware", nil, fqbn, "testdata/firmware", "firmware.ino"},
103+
// 17: importFile among multiple firmwares
104+
{"testdata/firmware/another_firmware.ino.bin", "", nil, fqbn, "testdata/firmware", "another_firmware.ino"},
100105
}
101106
for i, test := range tests {
102107
t.Run(fmt.Sprintf("SubTest%02d", i), func(t *testing.T) {

0 commit comments

Comments
 (0)