fs: flush on shutdown (#3009)

Fixes: #2950
This commit is contained in:
Zahari Dichev 2020-10-20 18:42:32 +03:00 committed by GitHub
parent 6d99e1c7de
commit 16e272ea4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 3 deletions

View File

@ -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)
}
}

View File

@ -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();