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: 2 additions & 3 deletions src/uu/head/src/head.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,16 +461,15 @@ fn uu_head(options: &HeadOptions) -> UResult<()> {
print_verbatim(file).unwrap();
println!(" <==");
}
head_file(&mut file_handle, options)?;
Ok(())
head_file(&mut file_handle, options).map(|_| ())
};
if let Err(err) = res {
let name = if file == "-" {
"standard input".into()
} else {
file.into()
};
return Err(HeadError::Io { name, err }.into());
show!(HeadError::Io { name, err });
}
first = false;
}
Expand Down
19 changes: 19 additions & 0 deletions tests/by-util/test_head.rs
Original file line number Diff line number Diff line change
Expand Up @@ -933,3 +933,22 @@ fn test_do_not_attempt_to_read_a_directory() {
.fails_with_code(1)
.stderr_contains("error reading '.'");
}

// When passed multiple files, process all files even if one fails
#[cfg(target_os = "linux")]
#[test]
#[cfg_attr(wasi_runner, ignore = "WASI sandbox: host paths (/proc) not visible")]
fn test_file_after_fail() {
let scene = TestScenario::new(util_name!());
let fixtures = &scene.fixtures;

fixtures.write("a", "a");

scene
.ucmd()
.args(&["/proc/self/mem", "a"])
.fails_with_code(1)
.stdout_contains("==> /proc/self/mem <==\n")
.stderr_contains("head: error reading '/proc/self/mem'")
.stdout_contains("==> a <==\na");
}
Loading