tools: Avoid leaving extra data at the end of copied files

The copyfile() implementation has strange behaviour if the destination
file already exists. Update it to ensure that any existing data in the
destination file is dropped.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass 2021-11-12 12:28:05 -07:00
parent e291a5c9a2
commit 7ae46c3579
2 changed files with 3 additions and 1 deletions

View file

@ -134,7 +134,7 @@ int copyfile(const char *src, const char *dst)
goto out;
}
fd_dst = open(dst, O_WRONLY | O_CREAT, 0666);
fd_dst = open(dst, O_WRONLY | O_CREAT | O_TRUNC, 0666);
if (fd_dst < 0) {
printf("Can't open file %s (%s)\n", dst, strerror(errno));
goto out;