Skip to content

Commit

Permalink
updater.go: replace os.WriteFile with file.Write() (#669)
Browse files Browse the repository at this point in the history
* Update updater.go

replace os.WriteFile with file.Write()

Signed-off-by: udf2457 <[email protected]>

* Update metadata/updater/updater.go

File is closed on all branches in the code, removing this.

Signed-off-by: Fredrik Skogman <[email protected]>

---------

Signed-off-by: udf2457 <[email protected]>
Signed-off-by: Fredrik Skogman <[email protected]>
Co-authored-by: Fredrik Skogman <[email protected]>
  • Loading branch information
udf2457 and kommendorkapten authored Jan 22, 2025
1 parent 830edf8 commit 110bec9
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions metadata/updater/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,11 +596,22 @@ func (update *Updater) persistMetadata(roleName string, data []byte) error {
if err != nil {
return err
}
defer file.Close()
// change the file permissions to our desired permissions
err = file.Chmod(0644)
if err != nil {
// close and delete the temporary file if there was an error while writing
file.Close()
errRemove := os.Remove(file.Name())
if errRemove != nil {
log.Info("Failed to delete temporary file", "name", file.Name())
}
return err
}
// write the data content to the temporary file
err = os.WriteFile(file.Name(), data, 0644)
_, err = file.Write(data)
if err != nil {
// delete the temporary file if there was an error while writing
// close and delete the temporary file if there was an error while writing
file.Close()
errRemove := os.Remove(file.Name())
if errRemove != nil {
log.Info("Failed to delete temporary file", "name", file.Name())
Expand Down

0 comments on commit 110bec9

Please sign in to comment.