removeSecure() should close the file before removing it on Windows (#32948)

* `removeSecure()` should close the file before removing it on Windows

* Do not return early if `Close()` returns an error
This commit is contained in:
Grzegorz Zdunek
2023-10-04 15:31:52 +00:00
committed by GitHub
parent c31e07841a
commit dffb5620b3
+4 -1
View File
@@ -323,7 +323,10 @@ func removeSecure(filePath string, fi os.FileInfo) error {
}
}
}
return trace.ConvertSystemError(os.Remove(filePath))
// The file should be closed before removing it on Windows.
closeErr := trace.ConvertSystemError(f.Close())
removeErr := trace.ConvertSystemError(os.Remove(filePath))
return trace.NewAggregate(closeErr, removeErr)
} else {
removeErr := os.Remove(filePath)
if f != nil {