Skip to content

Commit 6449244

Browse files
authored
Merge pull request #26 from arduino/skip_restore_binary
Added sanity check for restore_firmware flag
2 parents 117385c + 3617c47 commit 6449244

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

Diff for: main.go

+18-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/arduino/FirmwareUploader/modules/winc"
1515
"github.com/arduino/FirmwareUploader/utils"
1616
"github.com/arduino/FirmwareUploader/utils/context"
17+
"github.com/arduino/go-paths-helper"
1718
)
1819

1920
var ctx = &context.Context{}
@@ -25,7 +26,7 @@ func init() {
2526
flag.StringVar(&ctx.FirmwareFile, "firmware", "", "firmware file to flash")
2627
flag.BoolVar(&ctx.ReadAll, "read", false, "read all firmware and output to stdout")
2728
flag.StringVar(&ctx.FWUploaderBinary, "flasher", "", "firmware upload binary (precompiled for the right target)")
28-
flag.StringVar(&ctx.BinaryToRestore, "restore_binary", "", "firmware upload binary (precompiled for the right target)")
29+
flag.StringVar(&ctx.BinaryToRestore, "restore_binary", "", "binary to restore after the firmware upload (precompiled for the right target)")
2930
flag.StringVar(&ctx.ProgrammerPath, "programmer", "", "path of programmer in use (avrdude/bossac)")
3031
flag.StringVar(&ctx.Model, "model", "", "module model (winc, nina or sara)")
3132
flag.StringVar(&ctx.Compatible, "get_available_for", "", "Ask for available firmwares matching a given board")
@@ -44,6 +45,22 @@ func main() {
4445
log.Fatal("Please specify a serial port")
4546
}
4647

48+
if ctx.BinaryToRestore != "" {
49+
// sanity check for BinaryToRestore
50+
f := paths.New(ctx.BinaryToRestore)
51+
info, err := f.Stat()
52+
if err != nil {
53+
log.Fatalf("Error opening restore_binary: %s", err)
54+
}
55+
if info.IsDir() {
56+
log.Fatalf("Error opening restore_binary: is a directory...")
57+
}
58+
if info.Size() == 0 {
59+
log.Println("WARNING: restore_binary is empty! Will not restore binary after upload.")
60+
ctx.BinaryToRestore = ""
61+
}
62+
}
63+
4764
retry := 0
4865
for {
4966
var ctxCopy context.Context

0 commit comments

Comments
 (0)