Skip to content
Myr

Truncate export files before rewriting results

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Peter · committed by David Peter · parent 30a2b61 · Browse files · 1 file+5 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+5 added−1 removed

  • other:+5 added−1 removed

1 file+5 added−1 removed

modified:src/export/mod.rs+5 added-1 removed
156 unmodified lines
157}158159/// Write the given content to a file with the specified name160fn write_to_file(filename: &str, content: &[u8]) -> Result<()> {161 let mut file = OpenOptions::new().write(true).open(filename)?;161 let mut file = OpenOptions::new()162 .write(true)163 // Avoid leaving trailing bytes when the new export is shorter.164 .truncate(true)165 .open(filename)?;166 file.write_all(content)167 .with_context(|| format!("Failed to export results to '{filename}'"))168}