From 16e272ea4bcfbdc5aa3a0e36e9a3d3a639af4473 Mon Sep 17 00:00:00 2001 From: Zahari Dichev Date: Tue, 20 Oct 2020 18:42:32 +0300 Subject: fs: flush on shutdown (#3009) Fixes: #2950 --- tokio/src/fs/file.rs | 5 ++--- tokio/tests/fs_file.rs | 13 +++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/tokio/src/fs/file.rs b/tokio/src/fs/file.rs index 8b385117..7c71f483 100644 --- a/tokio/src/fs/file.rs +++ b/tokio/src/fs/file.rs @@ -682,9 +682,8 @@ impl AsyncWrite for File { inner.poll_flush(cx) } - fn poll_shutdown(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll> { - // Flush is a noop for files so it's fine not to call it. - Poll::Ready(Ok(())) + fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { + self.poll_flush(cx) } } diff --git a/tokio/tests/fs_file.rs b/tokio/tests/fs_file.rs index eee9a5b5..d5b56e6e 100644 --- a/tokio/tests/fs_file.rs +++ b/tokio/tests/fs_file.rs @@ -37,6 +37,19 @@ async fn basic_write() { assert_eq!(file, HELLO); } +#[tokio::test] +async fn basic_write_and_shutdown() { + let tempfile = tempfile(); + + let mut file = File::create(tempfile.path()).await.unwrap(); + + file.write_all(HELLO).await.unwrap(); + file.shutdown().await.unwrap(); + + let file = std::fs::read(tempfile.path()).unwrap(); + assert_eq!(file, HELLO); +} + #[tokio::test] async fn coop() { let mut tempfile = tempfile(); -- cgit v1.2.3