mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-09-25 12:00:35 +00:00
fs: preserve max_buf_size
when cloning a File
(#7593)
This commit is contained in:
parent
03bb6e29b1
commit
044eaa1a41
@ -465,7 +465,9 @@ impl File {
|
||||
self.inner.lock().await.complete_inflight().await;
|
||||
let std = self.std.clone();
|
||||
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
|
||||
|
@ -15,6 +15,22 @@ async fn path_read_write() {
|
||||
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 {
|
||||
tempfile::tempdir().unwrap()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user