Skip to content

Commit 743254d

Browse files
deadprogramaykevl
authored andcommitted
main: use simpler file copy instead of file renaming to avoid issues on nrf52840 UF2 bootloaders
Signed-off-by: deadprogram <[email protected]>
1 parent 9d625a1 commit 743254d

File tree

1 file changed

+8
-18
lines changed

1 file changed

+8
-18
lines changed

main.go

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,33 +58,23 @@ func moveFile(src, dst string) error {
5858
return os.Remove(src)
5959
}
6060

61-
// copyFile copies the given file from src to dst. It copies first to a .tmp
62-
// file which is then moved over a possibly already existing file at the
63-
// destination.
61+
// copyFile copies the given file from src to dst. It can copy over
62+
// a possibly already existing file at the destination.
6463
func copyFile(src, dst string) error {
65-
inf, err := os.Open(src)
64+
source, err := os.Open(src)
6665
if err != nil {
6766
return err
6867
}
69-
defer inf.Close()
70-
outpath := dst + ".tmp"
71-
outf, err := os.Create(outpath)
72-
if err != nil {
73-
return err
74-
}
75-
76-
_, err = io.Copy(outf, inf)
77-
if err != nil {
78-
os.Remove(outpath)
79-
return err
80-
}
68+
defer source.Close()
8169

82-
err = outf.Close()
70+
destination, err := os.Create(dst)
8371
if err != nil {
8472
return err
8573
}
74+
defer destination.Close()
8675

87-
return os.Rename(dst+".tmp", dst)
76+
_, err = io.Copy(destination, source)
77+
return err
8878
}
8979

9080
// Build compiles and links the given package and writes it to outpath.

0 commit comments

Comments
 (0)