Skip to content

Commit e9b9baa

Browse files
committed
coreutils: Fail with invalid binary name
1 parent 450e7cf commit e9b9baa

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed

src/bin/coreutils.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,12 @@ fn main() {
6565
if let Some(util) = validation::find_prefixed_util(binary_as_util, utils.keys().copied()) {
6666
// prefixed util => replace 0th (aka, executable name) argument
6767
Some(OsString::from(util))
68-
} else {
69-
// unmatched binary name => regard as multi-binary container and advance argument list
68+
} else if binary_as_util.ends_with("coreutils") {
7069
uucore::set_utility_is_second_arg();
7170
args.next()
71+
} else {
72+
println!("coreutils: I was probably called as symlink to false");
73+
process::exit(1);
7274
};
7375

7476
// 0th argument equals util name?

tests/test_util_name.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ fn util_non_utf8_name_help() {
177177
#[test]
178178
#[cfg(unix)]
179179
fn util_invalid_name_invalid_command() {
180-
use std::process::{Command, Stdio};
180+
use std::process::Command;
181181

182182
let scenario = TestScenario::new("invalid_name");
183183
symlink_file(&scenario.bin_path, scenario.fixtures.plus("invalid_name")).unwrap();
@@ -186,20 +186,11 @@ fn util_invalid_name_invalid_command() {
186186
return;
187187
}
188188

189-
let child = Command::new(scenario.fixtures.plus("invalid_name"))
190-
.arg("definitely_invalid")
191-
.stdin(Stdio::piped())
192-
.stdout(Stdio::piped())
193-
.stderr(Stdio::piped())
194-
.spawn()
195-
.unwrap();
196-
let output = child.wait_with_output().unwrap();
197-
assert_eq!(output.status.code(), Some(1));
198-
assert_eq!(output.stdout, b"");
199-
assert_eq!(
200-
output.stderr,
201-
b"definitely_invalid: function/utility not found\n"
202-
);
189+
let code = Command::new(scenario.fixtures.plus("invalid_name"))
190+
.status()
191+
.unwrap()
192+
.code();
193+
assert_eq!(code, Some(1)); //for GNU compat
203194
}
204195

205196
#[test]

0 commit comments

Comments
 (0)