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

safely write state files #1357

Closed
camerondavison opened this issue Jun 27, 2016 · 1 comment · Fixed by #1358
Closed

safely write state files #1357

camerondavison opened this issue Jun 27, 2016 · 1 comment · Fixed by #1358

Comments

@camerondavison
Copy link
Contributor

Currently

if err := ioutil.WriteFile(path, buf, 0600); err != nil {
is not writing files to disk safely.

According to golang docs WriteFile https://golang.org/pkg/io/ioutil/#WriteFile will truncate a file that exists before writing to it.

Given that setState is getting called all over the place this introduces a whole bunch of potential states in history where the json state file is empty.

The code should write to a temp file and then mv the temp file over the existing file (which in unix can be an atomic operation) It is important that the temp file lives in the exact same directory as well, because it can only be somewhat assure to be atomic if it is just changing inode table entries.

@github-actions
Copy link

I'm going to lock this issue because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants