Cherry pick more defensive file copying from commit 4a50b40305cd6a4628d2bf0a086cba674ece22d1.
Cherry pick more defensive file copying from commit 4a50b40305cd6a4628d2bf0a086cba674ece22d1.

cfe-lab/Kive,cfe-lab/Kive,cfe-lab/Kive,cfe-lab/Kive,cfe-lab/Kive