Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/uu/yes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ doctest = false
clap = { workspace = true }
itertools = { workspace = true }
fluent = { workspace = true }
rustix = { workspace = true, features = ["pipe"] }
uucore = { workspace = true, features = ["pipes"] }
rustix = { workspace = true, features = ["stdio", "pipe"] }
uucore = { workspace = true, features = ["fs", "pipes"] }

[[bin]]
name = "yes"
Expand Down
9 changes: 5 additions & 4 deletions src/uu/yes/src/yes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,16 @@ pub fn exec(mut bytes: Vec<u8>) -> io::Result<()> {

#[cfg(any(target_os = "linux", target_os = "android"))]
pub fn exec(mut bytes: Vec<u8>) -> io::Result<()> {
use uucore::io::RawWriter;
use uucore::pipes::{pipe, splice, tee};

const PAGE_SIZE: usize = 4096;
let aligned = PAGE_SIZE.is_multiple_of(bytes.len());
repeat_content_to_capacity(&mut bytes);
let bytes = bytes.as_slice();
let mut stdout = io::stdout(); // no need to lock with zero-copy
let stdout = rustix::stdio::stdout();
// improve throughput
let _ = rustix::pipe::fcntl_setpipe_size(&stdout, MAX_ROOTLESS_PIPE_SIZE);
let _ = rustix::pipe::fcntl_setpipe_size(stdout, MAX_ROOTLESS_PIPE_SIZE);
// don't show any error from fast-path and fallback to write for proper message
if let Ok((p_read, mut p_write)) = pipe()
&& p_write.write_all(bytes).is_ok()
Expand All @@ -132,15 +133,15 @@ pub fn exec(mut bytes: Vec<u8>) -> io::Result<()> {
remain -= s;
} else {
// avoid output breakage with reduced remain even if it would not happen
stdout.write_all(&bytes[bytes.len() - remain..])?;
RawWriter(stdout).write_all(&bytes[bytes.len() - remain..])?;
break 'hybrid;
}
}
}
}
}
// fallback
let mut stdout = stdout.lock();
let mut stdout = RawWriter(stdout);
loop {
stdout.write_all(bytes)?;
}
Expand Down
Loading