Skip to content

Commit

Permalink
Forcing a flush due to tokio::fs semantics.
Browse files Browse the repository at this point in the history
  • Loading branch information
Narsil committed Jan 7, 2025
1 parent e071841 commit 4ee445f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/api/tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -672,12 +672,20 @@ impl ApiRepo {
file.write_all(&committed.to_le_bytes()).await?;
}
}
tokio::fs::OpenOptions::new()
let mut f = tokio::fs::OpenOptions::new()
.write(true)
.open(&filename)
.await?
.await?;
f
.set_len(length as u64)
.await?;
// XXX Extremely important and not obvious.
// Tokio::fs doesn't guarantee data is written at the end of `.await`
// boundaries. Even though we await the `set_len` it may not have been
// committed to disk, leading to invalid rename.
// Forcing a flush forces the data (here the truncation) to be committed to disk
f.flush().await?;

progressbar.finish().await;
Ok(filename)
}
Expand Down

0 comments on commit 4ee445f

Please sign in to comment.