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
5 changes: 5 additions & 0 deletions src/uu/comm/src/comm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ pub fn are_files_identical(path1: &Path, path2: &Path) -> io::Result<bool> {
return Ok(false);
}

// only proceed if both are regular files
if !metadata1.is_file() || !metadata2.is_file() {
return Ok(false);
}

let file1 = File::open(path1)?;
let file2 = File::open(path2)?;

Expand Down
28 changes: 28 additions & 0 deletions tests/by-util/test_comm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -648,3 +648,31 @@ fn test_comm_eintr_handling() {
.stdout_contains("line2")
.stdout_contains("line3");
}

#[test]
#[cfg(unix)]
fn test_fifo() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;

at.mkfifo("fifo1");
at.mkfifo("fifo2");

let child = scene.ucmd().args(&["-13", "fifo1", "fifo2"]).run_no_wait();

let mut data1 = String::new();
for i in 0..10000 {
data1.push_str(&format!("{i:05}\n"));
}
let mut data2 = String::new();
for i in 0..9000 {
data2.push_str(&format!("{i:05}\n"));
}
// add one extra item which is only present in comm2
data2.push_str("99999\n");

std::fs::write(at.plus("fifo1"), data1).unwrap();
std::fs::write(at.plus("fifo2"), data2).unwrap();

child.wait().unwrap().success().stdout_is("99999\n");
}
Loading