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

writeDataAtomic() fixes #140

Merged
merged 2 commits into from
Sep 9, 2019
Merged

writeDataAtomic() fixes #140

merged 2 commits into from
Sep 9, 2019

Conversation

ebiggers
Copy link
Collaborator

No description provided.

@josephlr
Copy link
Member

Good catch! I really wish there was an easier way to do these sorts of things in Go, but alas.

Can you rebase onto #142 to make the CI happy?

Sync the temporary file before renaming it, to ensure that after a
crash, the destination file isn't zero-length or otherwise incomplete.

Also sync the directory after the rename, to ensure the rename has been
persisted before returning success.
Using a fixed temporary file name in a world-writable sticky directory
is problematic since another user can create the file first.

Use ioutil.TempFile() to do it properly.  It uses O_EXCL under the hood
to ensure the file is newly created.
@ebiggers
Copy link
Collaborator Author

Can you rebase onto #142 to make the CI happy?

Done.

Copy link
Member

@josephlr josephlr left a comment

Choose a reason for hiding this comment

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

Thanks for the fix. This is tricky to get right. Good catch!

@josephlr josephlr merged commit 237308a into google:master Sep 9, 2019
@ebiggers ebiggers deleted the writeDataAtomic-fixes branch September 10, 2019 02:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants