diff options
author | Zahari Dichev <zaharidichev@gmail.com> | 2020-10-20 18:42:32 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-20 17:42:32 +0200 |
commit | 16e272ea4bcfbdc5aa3a0e36e9a3d3a639af4473 (patch) | |
tree | fd7a23874a93ad1a45d788d7dc6b5352573aa4ed /tokio | |
parent | 6d99e1c7dec4c6a37c4c7bf2801bc82cc210351d (diff) |
fs: flush on shutdown (#3009)
Fixes: #2950
Diffstat (limited to 'tokio')
-rw-r--r-- | tokio/src/fs/file.rs | 5 | ||||
-rw-r--r-- | 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<Result<(), io::Error>> { - // 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<Result<(), io::Error>> { + 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 @@ -38,6 +38,19 @@ async fn basic_write() { } #[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(); tempfile.write_all(HELLO).unwrap(); |