Skip to content

Commit 44b9416

Browse files
committed
refactor: clarify variable names
1 parent 3df7e27 commit 44b9416

7 files changed

Lines changed: 44 additions & 42 deletions

File tree

fuzz/uufuzz/src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ where
9292
};
9393

9494
println!("Running test {:?}", &args[0..]);
95-
let (read_pipe_stdout, write_pipe_stdout) = match pipe() {
95+
let (stdout_pipe_reader, stdout_pipe_writer) = match pipe() {
9696
Ok(fds) => fds,
9797
Err(_) => {
9898
return CommandResult {
@@ -102,7 +102,7 @@ where
102102
};
103103
}
104104
};
105-
let (read_pipe_stderr, write_pipe_stderr) = match pipe() {
105+
let (stderr_pipe_reader, stderr_pipe_writer) = match pipe() {
106106
Ok(fds) => fds,
107107
Err(_) => {
108108
return CommandResult {
@@ -114,7 +114,7 @@ where
114114
};
115115

116116
// Redirect stdout and stderr to their respective pipes
117-
if dup2_stdout(&write_pipe_stdout).is_err() || dup2_stderr(&write_pipe_stderr).is_err() {
117+
if dup2_stdout(&stdout_pipe_writer).is_err() || dup2_stderr(&stderr_pipe_writer).is_err() {
118118
return CommandResult {
119119
stdout: "".to_string(),
120120
stderr: "Failed to redirect STDOUT_FILENO or STDERR_FILENO".to_string(),
@@ -156,8 +156,8 @@ where
156156
};
157157

158158
let (uumain_exit_status, captured_stdout, captured_stderr) = thread::scope(|s| {
159-
let out = s.spawn(|| read_from_fd(read_pipe_stdout));
160-
let err = s.spawn(|| read_from_fd(read_pipe_stderr));
159+
let out = s.spawn(|| read_from_fd(stdout_pipe_reader));
160+
let err = s.spawn(|| read_from_fd(stderr_pipe_reader));
161161
#[allow(clippy::unnecessary_to_owned)]
162162
// TODO: clippy wants us to use args.iter().cloned() ?
163163
let status = uumain_function(args.to_owned().into_iter());
@@ -167,8 +167,8 @@ where
167167
io::stdout().flush().unwrap();
168168
io::stderr().flush().unwrap();
169169
// Drop write ends to close them, allowing readers to get EOF
170-
drop(write_pipe_stdout);
171-
drop(write_pipe_stderr);
170+
drop(stdout_pipe_writer);
171+
drop(stderr_pipe_writer);
172172
// Restore stdout/stderr
173173
let _ = dup2_stdout(&original_stdout_fd_owned);
174174
let _ = dup2_stderr(&original_stderr_fd_owned);

src/uu/wc/src/count_fast.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,14 @@ fn count_bytes_using_splice(fd: &impl AsFd) -> Result<usize, usize> {
5555
}
5656
} else {
5757
// input is not pipe. needs broker to use splice() with additional cost
58-
let (pipe_rd, pipe_wr) = pipe::<false>(MAX_ROOTLESS_PIPE_SIZE).map_err(|_| 0_usize)?;
58+
let (pipe_reader, pipe_writer) =
59+
pipe::<false>(MAX_ROOTLESS_PIPE_SIZE).map_err(|_| 0_usize)?;
5960
loop {
60-
match splice(fd, &pipe_wr, MAX_ROOTLESS_PIPE_SIZE) {
61+
match splice(fd, &pipe_writer, MAX_ROOTLESS_PIPE_SIZE) {
6162
Ok(0) => return Ok(byte_count),
6263
Ok(res) => {
6364
byte_count += res;
64-
splice_exact(&pipe_rd, &null_file, res).map_err(|_| byte_count)?;
65+
splice_exact(&pipe_reader, &null_file, res).map_err(|_| byte_count)?;
6566
}
6667
Err(_) => return Err(byte_count),
6768
}

src/uu/yes/src/yes.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,19 @@ pub fn exec(mut bytes: Vec<u8>) -> io::Result<()> {
117117
// improve throughput
118118
let _ = rustix::pipe::fcntl_setpipe_size(&stdout, MAX_ROOTLESS_PIPE_SIZE);
119119
// don't show any error from fast-path and fallback to write for proper message
120-
if let Ok((p_read, mut p_write)) = pipe::<true>(MAX_ROOTLESS_PIPE_SIZE)
121-
&& p_write.write_all(bytes).is_ok()
120+
if let Ok((source_reader, mut source_writer)) = pipe::<true>(MAX_ROOTLESS_PIPE_SIZE)
121+
&& source_writer.write_all(bytes).is_ok()
122122
{
123-
if aligned && tee(&p_read, &stdout, MAX_ROOTLESS_PIPE_SIZE).is_ok() {
124-
while let Ok(1..) = tee(&p_read, &stdout, MAX_ROOTLESS_PIPE_SIZE) {}
125-
} else if let Ok((broker_read, broker_write)) = pipe::<true>(MAX_ROOTLESS_PIPE_SIZE) {
123+
if aligned && tee(&source_reader, &stdout, MAX_ROOTLESS_PIPE_SIZE).is_ok() {
124+
while let Ok(1..) = tee(&source_reader, &stdout, MAX_ROOTLESS_PIPE_SIZE) {}
125+
} else if let Ok((broker_reader, broker_writer)) = pipe::<true>(MAX_ROOTLESS_PIPE_SIZE) {
126126
// tee() cannot control offset and write to non-pipe
127-
'hybrid: while let Ok(mut remain) = tee(&p_read, &broker_write, MAX_ROOTLESS_PIPE_SIZE)
127+
'hybrid: while let Ok(mut remain) =
128+
tee(&source_reader, &broker_writer, MAX_ROOTLESS_PIPE_SIZE)
128129
{
129130
debug_assert!(remain == bytes.len(), "splice() should cleanup pipe");
130131
while remain > 0 {
131-
if let Ok(s) = splice(&broker_read, &stdout, remain) {
132+
if let Ok(s) = splice(&broker_reader, &stdout, remain) {
132133
remain -= s;
133134
} else {
134135
// avoid output breakage with reduced remain even if it would not happen

src/uucore/src/lib/features/buf_copy.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ mod tests {
5151
fn test_copy_stream() {
5252
let mut dest_file = new_temp_file();
5353

54-
let (mut pipe_read, mut pipe_write) = std::io::pipe().unwrap();
54+
let (mut pipe_reader, mut pipe_writer) = std::io::pipe().unwrap();
5555
let data = b"Hello, world!";
5656
let thread = thread::spawn(move || {
57-
pipe_write.write_all(data).unwrap();
57+
pipe_writer.write_all(data).unwrap();
5858
});
59-
copy_stream(&mut pipe_read, &mut dest_file).unwrap();
59+
copy_stream(&mut pipe_reader, &mut dest_file).unwrap();
6060
thread.join().unwrap();
6161

6262
// We would have been at the end already, so seek again to the start.

src/uucore/src/lib/features/pipes.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,16 @@ const KERNEL_DEFAULT_PIPE_SIZE: usize = 64 * 1024;
3030
pub fn pipe<const SIZE_REQUIRED: bool>(
3131
s: usize,
3232
) -> std::io::Result<(std::io::PipeReader, std::io::PipeWriter)> {
33-
let (read, write) = std::io::pipe()?;
33+
let (pipe_reader, pipe_writer) = std::io::pipe()?;
3434
// guard unnecessary syscall
3535
if s > KERNEL_DEFAULT_PIPE_SIZE {
36-
let r = fcntl_setpipe_size(&read, s);
36+
let r = fcntl_setpipe_size(&pipe_reader, s);
3737
if SIZE_REQUIRED {
3838
r?;
3939
}
4040
}
4141

42-
Ok((read, write))
42+
Ok((pipe_reader, pipe_writer))
4343
}
4444

4545
/// Less noisy wrapper around [`rustix::pipe::splice`].
@@ -120,7 +120,7 @@ where
120120
{
121121
static PIPE_CACHE: OnceLock<Option<(std::io::PipeReader, std::io::PipeWriter)>> =
122122
OnceLock::new();
123-
let Some((pipe_rd, pipe_wr)) = PIPE_CACHE
123+
let Some((pipe_reader, pipe_writer)) = PIPE_CACHE
124124
.get_or_init(|| pipe::<false>(MAX_ROOTLESS_PIPE_SIZE).ok())
125125
.as_ref()
126126
else {
@@ -133,18 +133,18 @@ where
133133
let _ = fcntl_setpipe_size(&mut *dest, MAX_ROOTLESS_PIPE_SIZE);
134134

135135
loop {
136-
match splice(&source, &pipe_wr, MAX_ROOTLESS_PIPE_SIZE) {
136+
match splice(&source, &pipe_writer, MAX_ROOTLESS_PIPE_SIZE) {
137137
Ok(0) => return Ok(false),
138138
Ok(n) => {
139-
if splice_exact(&pipe_rd, dest, n).is_err() {
139+
if splice_exact(&pipe_reader, dest, n).is_err() {
140140
// If the first splice manages to copy to the intermediate
141141
// pipe, but the second splice to stdout fails for some reason
142142
// we can recover by copying the data that we have from the
143143
// intermediate pipe to stdout using unbuffered read/write. Then
144144
// we tell the caller to fall back.
145145
debug_assert!(n <= MAX_ROOTLESS_PIPE_SIZE, "unexpected RAM usage");
146146
let mut drain = Vec::with_capacity(n);
147-
pipe_rd.take(n as u64).read_to_end(&mut drain)?;
147+
pipe_reader.take(n as u64).read_to_end(&mut drain)?;
148148
crate::io::RawWriter(&dest).write_all(&drain)?;
149149
return Ok(true);
150150
}

tests/by-util/test_cat.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ use uutests::util_name;
2323
#[test]
2424
fn test_cat_broken_pipe_nonzero_and_message() {
2525
use uutests::new_ucmd;
26-
let (read, write) = std::io::pipe().expect("Failed to create pipe");
26+
let (pipe_reader, pipe_writer) = std::io::pipe().expect("Failed to create pipe");
2727
// Close the read end to simulate a broken pipe on stdout
28-
drop(read);
28+
drop(pipe_reader);
2929
let content = (0..10000).map(|_| "x").collect::<String>();
3030

3131
// On Unix, SIGPIPE should lead to a non-zero exit; ensure process exits and fails
3232
new_ucmd!()
33-
.set_stdout(write)
33+
.set_stdout(pipe_writer)
3434
.pipe_in(content.as_bytes())
3535
.fails();
3636
}

tests/by-util/test_tee.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -262,19 +262,19 @@ mod linux_only {
262262
use uutests::new_ucmd;
263263

264264
fn make_broken_pipe() -> std::io::PipeWriter {
265-
let (read, write) = std::io::pipe().expect("Failed to create pipe");
265+
let (reader, writer) = std::io::pipe().expect("Failed to create pipe");
266266
// Drop the read end of the pipe
267-
drop(read);
267+
drop(reader);
268268
// Return the write end of the pipe
269-
write
269+
writer
270270
}
271271

272272
fn make_hanging_read() -> std::io::PipeReader {
273-
let (read, write) = std::io::pipe().expect("Failed to create pipe");
273+
let (reader, writer) = std::io::pipe().expect("Failed to create pipe");
274274
// PURPOSELY leak the write end of the pipe, so the read end hangs.
275-
std::mem::forget(write);
275+
std::mem::forget(writer);
276276
// Return the read end of the pipe
277-
read
277+
reader
278278
}
279279

280280
fn run_tee(proc: &mut UCommand) -> (String, CmdResult) {
@@ -725,13 +725,13 @@ fn test_output_error_flag_without_value_defaults_warn_nopipe() {
725725
#[cfg(all(unix, not(target_os = "freebsd")))]
726726
#[test]
727727
fn test_output_error_presence_only_broken_pipe_unix() {
728-
let (read, write) = std::io::pipe().expect("Failed to create pipe");
728+
let (reader, writer) = std::io::pipe().expect("Failed to create pipe");
729729
// Close the read end to simulate a broken pipe on stdout
730-
drop(read);
730+
drop(reader);
731731
let content = (0..10_000).map(|_| "x").collect::<String>();
732732
let result = new_ucmd!()
733733
.arg("--output-error") // presence-only flag
734-
.set_stdout(write)
734+
.set_stdout(writer)
735735
.pipe_in(content.as_bytes())
736736
.run();
737737

@@ -743,13 +743,13 @@ fn test_output_error_presence_only_broken_pipe_unix() {
743743
#[cfg(all(unix, not(target_os = "freebsd")))]
744744
#[test]
745745
fn test_broken_pipe_early_termination_stdout_only() {
746-
let (read, write) = std::io::pipe().expect("Failed to create pipe");
746+
let (reader, writer) = std::io::pipe().expect("Failed to create pipe");
747747
// Create a broken stdout
748-
drop(read);
748+
drop(reader);
749749
let content = (0..10_000).map(|_| "x").collect::<String>();
750750
let mut proc = new_ucmd!();
751751
let result = proc
752-
.set_stdout(write)
752+
.set_stdout(writer)
753753
.ignore_stdin_write_error()
754754
.pipe_in(content.as_bytes())
755755
.run();

0 commit comments

Comments
 (0)