mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-11-01 08:50:19 +00:00
Merge pull request #970 from sharkdp/codex/truncate-export-rewrites
Truncate export files before rewriting results
This commit is contained in:
1 file changed
+5
-1
+5
-1
@@ -158,7 +158,11 @@ impl ExportManager {
|
|||||||
|
|
||||||
/// Write the given content to a file with the specified name
|
/// Write the given content to a file with the specified name
|
||||||
fn write_to_file(filename: &str, content: &[u8]) -> Result<()> {
|
fn write_to_file(filename: &str, content: &[u8]) -> Result<()> {
|
||||||
let mut file = OpenOptions::new().write(true).open(filename)?;
|
let mut file = OpenOptions::new()
|
||||||
|
.write(true)
|
||||||
|
// Avoid leaving trailing bytes when the new export is shorter.
|
||||||
|
.truncate(true)
|
||||||
|
.open(filename)?;
|
||||||
file.write_all(content)
|
file.write_all(content)
|
||||||
.with_context(|| format!("Failed to export results to '{filename}'"))
|
.with_context(|| format!("Failed to export results to '{filename}'"))
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user