Closing files when files are removed

This commit is contained in:
Diptanu Choudhury 2016-09-23 22:17:53 -07:00
parent dae7f88118
commit 12c7873db2
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)