Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make config reloader file writes atomic #962

Merged
merged 2 commits into from
Mar 22, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pkg/reloader/reloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,14 @@ func (r *Reloader) apply(ctx context.Context) error {
return errors.Wrap(err, "expand environment variables")
}

if err := ioutil.WriteFile(r.cfgOutputFile, b, 0666); err != nil {
tmpFile := r.cfgOutputFile + ".tmp"
defer os.Remove(tmpFile)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can satisfy errcheck by

defer func(){ _ := os.Remove(tmpFile) }()

if err := ioutil.WriteFile(tmpFile, b, 0666); err != nil {
return errors.Wrap(err, "write file")
}
if err := os.Rename(tmpFile, r.cfgOutputFile); err != nil {
return errors.Wrap(err, "rename file")
}
}
}

Expand Down