Skip to content

Commit

Permalink
[v14] removeSecure() should close the file before removing it on Wi…
Browse files Browse the repository at this point in the history
…ndows (#32963)

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

* Do not return early if `Close()` returns an error
  • Loading branch information
gzdunek authored Oct 4, 2023
1 parent c7ba53c commit e781889
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/utils/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e781889

Please sign in to comment.