mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 07:27:21 +00:00
Fix a potential file leak
Previously, if a write or sync error occurred, we would not have called Close(). This commit refactors ReplaceFile() so that we are sure to call Close(), and also attempts to delete the temporary file if errors occur.
This commit is contained in:
@@ -62,6 +62,11 @@ func (DefaultFs) RemoveAll(path string) error {
|
||||
return os.RemoveAll(path)
|
||||
}
|
||||
|
||||
// Remove via os.RemoveAll
|
||||
func (DefaultFs) Remove(name string) error {
|
||||
return os.Remove(name)
|
||||
}
|
||||
|
||||
// ReadFile via ioutil.ReadFile
|
||||
func (DefaultFs) ReadFile(filename string) ([]byte, error) {
|
||||
return ioutil.ReadFile(filename)
|
||||
|
||||
Reference in New Issue
Block a user