Skip to content

Commit

Permalink
Added sanity check for restore_firmware flag
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaglie committed Apr 27, 2021
1 parent 117385c commit 3617c47
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion main.go
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/arduino/FirmwareUploader/modules/winc"
"github.com/arduino/FirmwareUploader/utils"
"github.com/arduino/FirmwareUploader/utils/context"
"github.com/arduino/go-paths-helper"
)

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

if ctx.BinaryToRestore != "" {
// sanity check for BinaryToRestore
f := paths.New(ctx.BinaryToRestore)
info, err := f.Stat()
if err != nil {
log.Fatalf("Error opening restore_binary: %s", err)
}
if info.IsDir() {
log.Fatalf("Error opening restore_binary: is a directory...")
}
if info.Size() == 0 {
log.Println("WARNING: restore_binary is empty! Will not restore binary after upload.")
ctx.BinaryToRestore = ""
}
}

retry := 0
for {
var ctxCopy context.Context
Expand Down

0 comments on commit 3617c47

Please sign in to comment.