Skip to content

Commit 5ec1d3e

Browse files
authored
Merge branch 'uutils:main' into cat-small-file
2 parents e6662bb + 02bc8e0 commit 5ec1d3e

5 files changed

Lines changed: 43 additions & 37 deletions

File tree

src/bin/coreutils.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ fn main() {
8585

8686
match util {
8787
"--list" => {
88-
// If --help is also present, show usage instead of list
89-
if args.any(|arg| arg == "--help" || arg == "-h") {
90-
usage(&utils, binary_as_util);
91-
process::exit(0);
88+
// we should fail with additional args https://github.com/uutils/coreutils/issues/11383#issuecomment-4082564058
89+
if args.next().is_some() {
90+
let _ = writeln!(io::stderr(), "coreutils: invalid argument");
91+
process::exit(1);
9292
}
9393
let mut out = io::stdout().lock();
9494
for util in utils.keys() {
@@ -156,8 +156,13 @@ fn main() {
156156
}
157157
}
158158
} else {
159-
// no arguments provided
160-
usage(&utils, binary_as_util);
161-
process::exit(0);
159+
// GNU just fails, but busybox tests needs usage
160+
// todo: patch the test suite instead
161+
if binary_as_util.ends_with("box") {
162+
usage(&utils, binary_as_util);
163+
} else {
164+
let _ = writeln!(io::stderr(), "coreutils: missing argument");
165+
}
166+
process::exit(1);
162167
}
163168
}

src/uu/ls/locales/en-US.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ ls-error-cannot-open-directory-bad-descriptor = cannot open directory {$path}: B
2222
ls-error-unknown-io-error = unknown io error: {$path}, '{$error}'
2323
ls-error-invalid-block-size = invalid --block-size argument {$size}
2424
ls-error-dired-and-zero-incompatible = --dired and --zero are incompatible
25+
ls-error-not-directory = cannot access {$path}: Not a directory
2526
ls-error-not-listing-already-listed = {$path}: not listing already-listed directory
2627
ls-error-invalid-time-style = invalid --time-style argument {$style}
2728
Possible values are:

src/uu/ls/src/ls.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ enum LsError {
6868
IOError(#[from] std::io::Error),
6969

7070
#[error("{}", match .1.kind() {
71+
ErrorKind::NotADirectory => translate!("ls-error-not-directory", "path" => .0.quote()),
7172
ErrorKind::NotFound => translate!("ls-error-cannot-access-no-such-file", "path" => .0.quote()),
7273
ErrorKind::PermissionDenied => match .1.raw_os_error().unwrap_or(1) {
7374
1 => translate!("ls-error-cannot-access-operation-not-permitted", "path" => .0.quote()),

src/uu/stdbuf/src/stdbuf.rs

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,9 @@ mod options {
3333

3434
#[cfg(all(
3535
not(feature = "feat_external_libstdbuf"),
36-
any(
37-
target_os = "linux",
38-
target_os = "android",
39-
target_os = "freebsd",
40-
target_os = "netbsd",
41-
target_os = "openbsd",
42-
target_os = "dragonfly"
43-
)
36+
unix,
37+
not(target_vendor = "apple"),
38+
not(target_os = "cygwin")
4439
))]
4540
const STDBUF_INJECT: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/libstdbuf.so"));
4641

@@ -84,29 +79,19 @@ enum ProgramOptionsError {
8479
ValueTooLarge(String),
8580
}
8681

87-
#[cfg(any(
88-
target_os = "linux",
89-
target_os = "android",
90-
target_os = "freebsd",
91-
target_os = "netbsd",
92-
target_os = "openbsd",
93-
target_os = "dragonfly"
94-
))]
95-
#[expect(
96-
clippy::unnecessary_wraps,
97-
reason = "fn sig must match on all platforms"
98-
)]
99-
fn preload_strings() -> UResult<(&'static str, &'static str)> {
100-
Ok(("LD_PRELOAD", "so"))
82+
#[cfg(all(unix, not(target_vendor = "apple"), not(target_os = "cygwin")))]
83+
fn preload_strings() -> (&'static str, &'static str) {
84+
("LD_PRELOAD", "so")
10185
}
10286

10387
#[cfg(target_vendor = "apple")]
104-
#[expect(
105-
clippy::unnecessary_wraps,
106-
reason = "fn sig must match on all platforms"
107-
)]
108-
fn preload_strings() -> UResult<(&'static str, &'static str)> {
109-
Ok(("DYLD_LIBRARY_PATH", "dylib"))
88+
fn preload_strings() -> (&'static str, &'static str) {
89+
("DYLD_LIBRARY_PATH", "dylib")
90+
}
91+
92+
#[cfg(target_os = "cygwin")]
93+
fn preload_strings() -> (&'static str, &'static str) {
94+
("LD_PRELOAD", "dll")
11095
}
11196

11297
fn check_option(matches: &ArgMatches, name: &str) -> Result<BufferType, ProgramOptionsError> {
@@ -149,7 +134,7 @@ fn get_preload_env(tmp_dir: &TempDir) -> UResult<(String, PathBuf)> {
149134
use std::fs::File;
150135
use std::io::Write;
151136

152-
let (preload, extension) = preload_strings()?;
137+
let (preload, extension) = preload_strings();
153138
let inject_path = tmp_dir.path().join("libstdbuf").with_extension(extension);
154139

155140
let mut file = File::create(&inject_path)?;
@@ -160,7 +145,7 @@ fn get_preload_env(tmp_dir: &TempDir) -> UResult<(String, PathBuf)> {
160145

161146
#[cfg(feature = "feat_external_libstdbuf")]
162147
fn get_preload_env(_tmp_dir: &TempDir) -> UResult<(String, PathBuf)> {
163-
let (preload, extension) = preload_strings()?;
148+
let (preload, extension) = preload_strings();
164149

165150
// Use the directory provided at compile time via LIBSTDBUF_DIR environment variable
166151
// This will fail to compile if LIBSTDBUF_DIR is not set, which is the desired behavior

tests/by-util/test_ls.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,20 @@ const COMMA_ARGS: &[&str] = &["-m", "--format=commas", "--for=commas"];
5757

5858
const COLUMN_ARGS: &[&str] = &["-C", "--format=columns", "--for=columns"];
5959

60+
#[test]
61+
#[cfg(unix)]
62+
fn test_directory_in_file() {
63+
let scene = TestScenario::new(util_name!());
64+
let at = &scene.fixtures;
65+
at.touch("file");
66+
67+
scene
68+
.ucmd()
69+
.arg("file/missing")
70+
.fails_with_code(2)
71+
.stderr_is("ls: cannot access 'file/missing': Not a directory\n");
72+
}
73+
6074
#[test]
6175
fn test_invalid_flag() {
6276
new_ucmd!()

0 commit comments

Comments
 (0)