From aedc1023e677fa1cfa0c5da260e9250906eb4aad Mon Sep 17 00:00:00 2001 From: "Kevin C. Wells" Date: Fri, 9 Feb 2018 15:49:35 -0800 Subject: [PATCH] Fix CopyFile bug Previously, helpers.CopyFile left off os.O_TRUNC, meaning that if the destination is larger than the source, the rest of the destination remained at the end. Now the file is overwritten completely. Signed-off-by: Kevin C. Wells --- helpers/helpers.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/helpers/helpers.go b/helpers/helpers.go index f6ffb60..d61feea 100644 --- a/helpers/helpers.go +++ b/helpers/helpers.go @@ -198,10 +198,9 @@ func UnpackFile(file string, dest string) error { return nil } -// CopyFile is used during the build process to copy a given file to the target -// instead of dealing with the particulars of hardlinking. +// CopyFile copies a file, overwriting the destination if it exists. func CopyFile(dest string, src string) error { - return copyFileWithFlags(dest, src, os.O_RDWR|os.O_CREATE) + return copyFileWithFlags(dest, src, os.O_RDWR|os.O_CREATE|os.O_TRUNC) } // CopyFileNoOverwrite copies a file only if the destination file does not exist.