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 <kevin.c.wells@intel.com>
This commit is contained in:
Kevin C. Wells
2018-02-09 16:47:40 -08:00
committed by tmarcu
parent e7823a3a7a
commit aedc1023e6
+2 -3
View File
@@ -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.