Skip to content

Commit 044eaa1

Browse files
authored
fs: preserve max_buf_size when cloning a File (#7593)
1 parent 03bb6e2 commit 044eaa1

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

tokio/src/fs/file.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,9 @@ impl File {
465465
self.inner.lock().await.complete_inflight().await;
466466
let std = self.std.clone();
467467
let std_file = asyncify(move || std.try_clone()).await?;
468-
Ok(File::from_std(std_file))
468+
let mut file = File::from_std(std_file);
469+
file.set_max_buf_size(self.max_buf_size);
470+
Ok(file)
469471
}
470472

471473
/// Destructures `File` into a [`std::fs::File`]. This function is

tokio/tests/fs.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@ async fn path_read_write() {
1515
assert_eq!(out, b"bytes");
1616
}
1717

18+
#[tokio::test]
19+
async fn try_clone_should_preserve_max_buf_size() {
20+
let buf_size = 128;
21+
let temp = tempdir();
22+
let dir = temp.path();
23+
24+
let mut file = fs::File::create(dir.join("try_clone_should_preserve_max_buf_size"))
25+
.await
26+
.unwrap();
27+
file.set_max_buf_size(buf_size);
28+
29+
let cloned = file.try_clone().await.unwrap();
30+
31+
assert_eq!(cloned.max_buf_size(), buf_size);
32+
}
33+
1834
fn tempdir() -> tempfile::TempDir {
1935
tempfile::tempdir().unwrap()
2036
}

0 commit comments

Comments
 (0)