Merge pull request #1742 from hashicorp/b-text-file-busy

Closing files when files are removed
This commit is contained in:
Alex Dadgar 2016-09-26 11:50:27 -07:00 committed by GitHub
commit ff2dc0b0a7
1 changed files with 2 additions and 0 deletions

View File

@ -514,11 +514,13 @@ func fileCopy(src, dst string, perm os.FileMode) error {
if err != nil {
return fmt.Errorf("Couldn't open src file %v: %v", src, err)
}
defer srcFile.Close()
dstFile, err := os.OpenFile(dst, os.O_WRONLY|os.O_CREATE, perm)
if err != nil {
return fmt.Errorf("Couldn't create destination file %v: %v", dst, err)
}
defer dstFile.Close()
if _, err := io.Copy(dstFile, srcFile); err != nil {
return fmt.Errorf("Couldn't copy %v to %v: %v", src, dst, err)