fs: preserve max_buf_size when cloning a File (#7593)

This commit is contained in:
Martin Grigorov 2025-09-09 11:34:35 +03:00 committed by GitHub
parent 03bb6e29b1
commit 044eaa1a41
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 1 deletions

View File

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

View File

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