Skip to content

Conversation

tronical
Copy link
Member

@tronical tronical commented Aug 8, 2025

Quoting from the BufWriter docs:

It is critical to call flush before BufWriter is dropped. Though
dropping will attempt to flush the contents of the buffer, any errors
that happen in the process of dropping will be ignored. Calling flush
ensures that the buffer is empty and thus dropping will not even
attempt file operations.

Quoting from the BufWriter docs:

>It is critical to call flush before BufWriter<W> is dropped. Though
>dropping will attempt to flush the contents of the buffer, any errors
>that happen in the process of dropping will be ignored. Calling flush
>ensures that the buffer is empty and thus dropping will not even
>attempt file operations.
write!(&mut BufWriter::new(std::fs::File::create(&cpp_file_name)?), "{cpp_file}")?;
let mut cpp_writer = BufWriter::new(std::fs::File::create(&cpp_file_name)?);
write!(&mut cpp_writer, "{cpp_file}")?;
cpp_writer.flush()?;
Copy link
Contributor

@ubruhin ubruhin Aug 8, 2025

Choose a reason for hiding this comment

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

Actually BufWriter could even be removed here I guess, as the whole file is written at once(?) Same applies to two other locations. EDIT: Hmm well maybe I'm wrong, I don't know exactly what's the type of cpp_file and how it gets written to the stream.

And btw, in my fork I still have the patch from #9092 included, so what I've actually tested is the combination of those two changes. Generally I'd still vote to implement the atomic file writes as long as there's no serious drawback (I didn't check the details about it).

@tronical tronical merged commit b70a008 into master Aug 20, 2025
40 checks passed
@tronical tronical deleted the simon/flush-bufwriter branch August 20, 2025 08:22
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.

3 participants