mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-07 00:00:08 +02:00
fs: preserve max_buf_size when cloning a File (#7593)
This commit is contained in:
@@ -465,7 +465,9 @@ impl File {
|
|||||||
self.inner.lock().await.complete_inflight().await;
|
self.inner.lock().await.complete_inflight().await;
|
||||||
let std = self.std.clone();
|
let std = self.std.clone();
|
||||||
let std_file = asyncify(move || std.try_clone()).await?;
|
let std_file = asyncify(move || std.try_clone()).await?;
|
||||||
Ok(File::from_std(std_file))
|
let mut file = File::from_std(std_file);
|
||||||
|
file.set_max_buf_size(self.max_buf_size);
|
||||||
|
Ok(file)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Destructures `File` into a [`std::fs::File`]. This function is
|
/// Destructures `File` into a [`std::fs::File`]. This function is
|
||||||
|
|||||||
@@ -15,6 +15,22 @@ async fn path_read_write() {
|
|||||||
assert_eq!(out, b"bytes");
|
assert_eq!(out, b"bytes");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn try_clone_should_preserve_max_buf_size() {
|
||||||
|
let buf_size = 128;
|
||||||
|
let temp = tempdir();
|
||||||
|
let dir = temp.path();
|
||||||
|
|
||||||
|
let mut file = fs::File::create(dir.join("try_clone_should_preserve_max_buf_size"))
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
file.set_max_buf_size(buf_size);
|
||||||
|
|
||||||
|
let cloned = file.try_clone().await.unwrap();
|
||||||
|
|
||||||
|
assert_eq!(cloned.max_buf_size(), buf_size);
|
||||||
|
}
|
||||||
|
|
||||||
fn tempdir() -> tempfile::TempDir {
|
fn tempdir() -> tempfile::TempDir {
|
||||||
tempfile::tempdir().unwrap()
|
tempfile::tempdir().unwrap()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user