mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-18 03:24:00 +00:00
main: use simpler file copy instead of file renaming to avoid issues on nrf52840 UF2 bootloaders
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
@@ -58,33 +58,23 @@ func moveFile(src, dst string) error {
|
|||||||
return os.Remove(src)
|
return os.Remove(src)
|
||||||
}
|
}
|
||||||
|
|
||||||
// copyFile copies the given file from src to dst. It copies first to a .tmp
|
// copyFile copies the given file from src to dst. It can copy over
|
||||||
// file which is then moved over a possibly already existing file at the
|
// a possibly already existing file at the destination.
|
||||||
// destination.
|
|
||||||
func copyFile(src, dst string) error {
|
func copyFile(src, dst string) error {
|
||||||
inf, err := os.Open(src)
|
source, err := os.Open(src)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer inf.Close()
|
|
||||||
outpath := dst + ".tmp"
|
|
||||||
outf, err := os.Create(outpath)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
defer source.Close()
|
||||||
|
|
||||||
_, err = io.Copy(outf, inf)
|
destination, err := os.Create(dst)
|
||||||
if err != nil {
|
|
||||||
os.Remove(outpath)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = outf.Close()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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.
|
// Build compiles and links the given package and writes it to outpath.
|
||||||
|
|||||||
Reference in New Issue
Block a user