From 743254d5bcdd355932a7d4c29cab54817deac77c Mon Sep 17 00:00:00 2001 From: deadprogram Date: Tue, 25 Aug 2020 00:45:56 +0200 Subject: [PATCH] main: use simpler file copy instead of file renaming to avoid issues on nrf52840 UF2 bootloaders Signed-off-by: deadprogram --- main.go | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/main.go b/main.go index cd7c7269..1e4a0620 100644 --- a/main.go +++ b/main.go @@ -58,33 +58,23 @@ func moveFile(src, dst string) error { return os.Remove(src) } -// copyFile copies the given file from src to dst. It copies first to a .tmp -// file which is then moved over a possibly already existing file at the -// destination. +// copyFile copies the given file from src to dst. It can copy over +// a possibly already existing file at the destination. func copyFile(src, dst string) error { - inf, err := os.Open(src) - if err != nil { - return err - } - defer inf.Close() - outpath := dst + ".tmp" - outf, err := os.Create(outpath) + source, err := os.Open(src) if err != nil { return err } + defer source.Close() - _, err = io.Copy(outf, inf) - if err != nil { - os.Remove(outpath) - return err - } - - err = outf.Close() + destination, err := os.Create(dst) if err != nil { return err } + defer destination.Close() - return os.Rename(dst+".tmp", dst) + _, err = io.Copy(destination, source) + return err } // Build compiles and links the given package and writes it to outpath.