main: use simpler file copy instead of file renaming to avoid issues on nrf52840 UF2 bootloaders
Signed-off-by: deadprogram <ron@hybridgroup.com>
Этот коммит содержится в:
родитель
9d625a1ccb
коммит
743254d5bc
1 изменённых файлов: 8 добавлений и 18 удалений
26
main.go
26
main.go
|
@ -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.
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче