From 5ab510d2b9633f70c03e32fc76254e9e6cfd34e6 Mon Sep 17 00:00:00 2001 From: Lars Quentin Date: Mon, 26 Feb 2024 11:44:09 +0100 Subject: [PATCH] fix bug: delete file if partial write was detected --- blackheap/src/benchmark.rs | 6 ++++++ blackheap/src/main.rs | 1 + 2 files changed, 7 insertions(+) diff --git a/blackheap/src/benchmark.rs b/blackheap/src/benchmark.rs index 2e0f0e7..c67aca0 100644 --- a/blackheap/src/benchmark.rs +++ b/blackheap/src/benchmark.rs @@ -152,6 +152,12 @@ pub fn save_and_update_progress( ); let file_path = format!("{}/{}.txt", &dir, access_size,); fs::create_dir_all(dir)?; + + /* If it already exists but we did still benchmark, it was most likely interrupted while writing... */ + if Path::new(&file_path).exists() { + fs::remove_file(&file_path)?; + } + File::create(&file_path)?; /* we save it as newline seperated f64s */ diff --git a/blackheap/src/main.rs b/blackheap/src/main.rs index 20e6b9a..e3a39c2 100644 --- a/blackheap/src/main.rs +++ b/blackheap/src/main.rs @@ -36,6 +36,7 @@ fn main() { for b in benchmarks.iter() { /* Which access sizes do we still have to do? */ let missing_access_sizes = { + /* To make the borrow checker happy */ let tmp_progress = progress.clone(); tmp_progress .get_missing_access_sizes(b)