diff --git a/fuzz/uufuzz/src/lib.rs b/fuzz/uufuzz/src/lib.rs index 43085ace71b..151a5f71b80 100644 --- a/fuzz/uufuzz/src/lib.rs +++ b/fuzz/uufuzz/src/lib.rs @@ -11,11 +11,11 @@ use rand::RngExt; use rand::prelude::IndexedRandom; use rustix::io::dup; use rustix::io::read; -use rustix::pipe::pipe; use rustix::stdio::{dup2_stderr, dup2_stdin, dup2_stdout}; use std::env::temp_dir; use std::ffi::OsString; use std::fs::File; +use std::io::pipe; use std::io::{Seek, SeekFrom, Write}; use std::process::{Command, Stdio}; use std::sync::atomic::Ordering; diff --git a/src/uucore/src/lib/features/buf_copy.rs b/src/uucore/src/lib/features/buf_copy.rs index c5242ccd6ec..1891a48785f 100644 --- a/src/uucore/src/lib/features/buf_copy.rs +++ b/src/uucore/src/lib/features/buf_copy.rs @@ -51,9 +51,7 @@ mod tests { fn test_copy_stream() { let mut dest_file = new_temp_file(); - let (pipe_read, pipe_write) = rustix::pipe::pipe().unwrap(); - let mut pipe_read: File = pipe_read.into(); - let mut pipe_write: File = pipe_write.into(); + let (mut pipe_read, mut pipe_write) = std::io::pipe().unwrap(); let data = b"Hello, world!"; let thread = thread::spawn(move || { pipe_write.write_all(data).unwrap(); diff --git a/src/uucore/src/lib/features/pipes.rs b/src/uucore/src/lib/features/pipes.rs index d3ee83300e7..f4411edbcae 100644 --- a/src/uucore/src/lib/features/pipes.rs +++ b/src/uucore/src/lib/features/pipes.rs @@ -27,8 +27,10 @@ const KERNEL_DEFAULT_PIPE_SIZE: usize = 64 * 1024; /// used for resolving the limitation for splice: one of a input or output should be pipe #[inline] #[cfg(any(target_os = "linux", target_os = "android"))] -pub fn pipe(s: usize) -> std::io::Result<(File, File)> { - let (read, write) = rustix::pipe::pipe()?; +pub fn pipe( + s: usize, +) -> std::io::Result<(std::io::PipeReader, std::io::PipeWriter)> { + let (read, write) = std::io::pipe()?; // guard unnecessary syscall if s > KERNEL_DEFAULT_PIPE_SIZE { let r = fcntl_setpipe_size(&read, s); @@ -37,7 +39,7 @@ pub fn pipe(s: usize) -> std::io::Result<(File, File) } } - Ok((File::from(read), File::from(write))) + Ok((read, write)) } /// Less noisy wrapper around [`rustix::pipe::splice`]. @@ -116,7 +118,8 @@ where R: Read + AsFd, S: AsFd, { - static PIPE_CACHE: OnceLock> = OnceLock::new(); + static PIPE_CACHE: OnceLock> = + OnceLock::new(); let Some((pipe_rd, pipe_wr)) = PIPE_CACHE .get_or_init(|| pipe::(MAX_ROOTLESS_PIPE_SIZE).ok()) .as_ref() @@ -160,7 +163,8 @@ pub fn send_n_bytes( mut target: impl Write + AsFd, n: u64, ) -> std::io::Result { - static PIPE_CACHE: OnceLock> = OnceLock::new(); + static PIPE_CACHE: OnceLock> = + OnceLock::new(); let pipe_size = MAX_ROOTLESS_PIPE_SIZE.min(n as usize); let mut n = n; let mut bytes_written: u64 = 0; diff --git a/tests/by-util/test_cat.rs b/tests/by-util/test_cat.rs index b69d2c17e45..df2765b79b6 100644 --- a/tests/by-util/test_cat.rs +++ b/tests/by-util/test_cat.rs @@ -23,10 +23,9 @@ use uutests::util_name; #[test] fn test_cat_broken_pipe_nonzero_and_message() { use uutests::new_ucmd; - let (read, write) = rustix::pipe::pipe().expect("Failed to create pipe"); + let (read, write) = std::io::pipe().expect("Failed to create pipe"); // Close the read end to simulate a broken pipe on stdout drop(read); - let write: File = write.into(); let content = (0..10000).map(|_| "x").collect::(); // On Unix, SIGPIPE should lead to a non-zero exit; ensure process exits and fails diff --git a/tests/by-util/test_comm.rs b/tests/by-util/test_comm.rs index ab1bb7ecb37..d082284485f 100644 --- a/tests/by-util/test_comm.rs +++ b/tests/by-util/test_comm.rs @@ -691,10 +691,8 @@ fn test_comm_anonymous_pipes() { let scene = TestScenario::new(util_name!()); // Open two anonymous pipes - let (comm1_reader, comm1_writer) = rustix::pipe::pipe().unwrap(); - let mut comm1_writer: std::fs::File = comm1_writer.into(); - let (comm2_reader, comm2_writer) = rustix::pipe::pipe().unwrap(); - let mut comm2_writer: std::fs::File = comm2_writer.into(); + let (comm1_reader, mut comm1_writer) = std::io::pipe().unwrap(); + let (comm2_reader, mut comm2_writer) = std::io::pipe().unwrap(); // comm reads the data in chunks // make content large enough, so that at least two chunks are read diff --git a/tests/by-util/test_paste.rs b/tests/by-util/test_paste.rs index c81f6f1b2c0..cfe099c8b93 100644 --- a/tests/by-util/test_paste.rs +++ b/tests/by-util/test_paste.rs @@ -450,12 +450,12 @@ fn test_paste_non_utf8_paths() { } #[cfg(target_os = "linux")] -fn make_broken_pipe() -> std::fs::File { - let (read, write) = rustix::pipe::pipe().expect("Failed to create pipe"); +fn make_broken_pipe() -> std::io::PipeWriter { + let (read, write) = std::io::pipe().expect("Failed to create pipe"); // Drop the read end so writes fail with EPIPE. drop(read); - - write.into() + // Return the write end of the pipe + write } #[test] diff --git a/tests/by-util/test_tee.rs b/tests/by-util/test_tee.rs index 50c8dbf497e..2948eaa045b 100644 --- a/tests/by-util/test_tee.rs +++ b/tests/by-util/test_tee.rs @@ -256,26 +256,25 @@ mod linux_only { use uutests::util::{AtPath, CmdResult, UCommand}; use std::fmt::Write; - use std::fs::File; use std::process::Stdio; use std::time::Duration; use uutests::at_and_ucmd; use uutests::new_ucmd; - fn make_broken_pipe() -> File { - let (read, write) = rustix::pipe::pipe().expect("Failed to create pipe"); + fn make_broken_pipe() -> std::io::PipeWriter { + let (read, write) = std::io::pipe().expect("Failed to create pipe"); // Drop the read end of the pipe drop(read); - // Make the write end of the pipe into a Rust File - write.into() + // Return the write end of the pipe + write } - fn make_hanging_read() -> File { - let (read, write) = rustix::pipe::pipe().expect("Failed to create pipe"); + fn make_hanging_read() -> std::io::PipeReader { + let (read, write) = std::io::pipe().expect("Failed to create pipe"); // PURPOSELY leak the write end of the pipe, so the read end hangs. std::mem::forget(write); // Return the read end of the pipe - read.into() + read } fn run_tee(proc: &mut UCommand) -> (String, CmdResult) { @@ -726,10 +725,9 @@ fn test_output_error_flag_without_value_defaults_warn_nopipe() { #[cfg(all(unix, not(target_os = "freebsd")))] #[test] fn test_output_error_presence_only_broken_pipe_unix() { - let (read, write) = rustix::pipe::pipe().expect("Failed to create pipe"); + let (read, write) = std::io::pipe().expect("Failed to create pipe"); // Close the read end to simulate a broken pipe on stdout drop(read); - let write: std::fs::File = write.into(); let content = (0..10_000).map(|_| "x").collect::(); let result = new_ucmd!() .arg("--output-error") // presence-only flag @@ -745,10 +743,9 @@ fn test_output_error_presence_only_broken_pipe_unix() { #[cfg(all(unix, not(target_os = "freebsd")))] #[test] fn test_broken_pipe_early_termination_stdout_only() { - let (read, write) = rustix::pipe::pipe().expect("Failed to create pipe"); + let (read, write) = std::io::pipe().expect("Failed to create pipe"); // Create a broken stdout drop(read); - let write: std::fs::File = write.into(); let content = (0..10_000).map(|_| "x").collect::(); let mut proc = new_ucmd!(); let result = proc