From 9206a1418be69d4ad42f85c39ce46aa00312733b Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sun, 17 Sep 2023 15:55:57 +0200 Subject: [PATCH] ls: --dired will fail when -l is missing or when --hyperlink is used Currently, it is silently ignoring the option. * src/ls.c (decode_switches): implement the error * tests/ls/dired.sh: check that errors are generated --- src/ls.c | 9 +++++---- tests/ls/dired.sh | 4 ++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/ls.c b/src/ls.c index 5fe6e2725..8e8b21111 100644 --- a/src/ls.c +++ b/src/ls.c @@ -2377,10 +2377,11 @@ decode_switches (int argc, char **argv) dirname_quoting_options = clone_quoting_options (nullptr); set_char_quoting (dirname_quoting_options, ':', 1); - /* --dired is meaningful only with --format=long (-l) and sans --hyperlink. - Otherwise, ignore it. FIXME: warn about this? - Alternatively, make --dired imply --format=long? */ - dired &= (format == long_format) & !print_hyperlink; + if (dired && format != long_format) + error (LS_FAILURE, 0, _("--dired requires --format=long (-l)")); + + if (dired && print_hyperlink) + error (LS_FAILURE, 0, _("--dired and --hyperlink are incompatible")); if (eolbyte < dired) error (LS_FAILURE, 0, _("--dired and --zero are incompatible")); diff --git a/tests/ls/dired.sh b/tests/ls/dired.sh index 417d3b594..6dd9b4efa 100755 --- a/tests/ls/dired.sh +++ b/tests/ls/dired.sh @@ -19,6 +19,10 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ ls +ls --dired dir > out && fail=1 + +ls --hyperlink --dired dir > out && fail=1 + # Check with constant positions mkdir dir || framework_failure_ -- 2.39.2