]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
ls: --dired now implies long format with hyperlinks disabled
authorSylvestre Ledru <sylvestre@debian.org>
Sun, 17 Sep 2023 13:55:57 +0000 (15:55 +0200)
committerPádraig Brady <P@draigBrady.com>
Sun, 17 Sep 2023 17:47:50 +0000 (18:47 +0100)
Currently --dired is silently ignored
with conflicting output formats

* src/ls.c (decode_switches): Set default format and hyperlink mode
when the --dired option is specified.
* tests/ls/dired.sh: Check that formats are implied / overridden.
* NEWS: Mention the change in behavior.
* doc/coreutils.texi (ls invocation): Adjust --dired description.

NEWS
doc/coreutils.texi
src/ls.c
tests/ls/dired.sh

diff --git a/NEWS b/NEWS
index 2adea1e11f44912d043d1b3275c48563f39fe55b..118995dbc03685d17a6b5e54a27ba0ff59ea5459 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,11 @@ GNU coreutils NEWS                                    -*- outline -*-
   numfmt options like --suffix no longer have an arbitrary 127-byte limit.
   [bug introduced with numfmt in coreutils-8.21]
 
+** Changes in behavior
+
+  ls --dired now implies long format output without hyperlinks enabled,
+  and will take precedence over previously specified formats or hyperlink mode.
+
 
 * Noteworthy changes in release 9.4 (2023-08-29) [stable]
 
index 8aed79222fbd67f4207ce0fef1c78435b9492641..f7a2bda7c536adb4a83ee6ced56dbb968bb56294 100644 (file)
@@ -7890,9 +7890,9 @@ should either specify an explicit @option{--quoting-style=literal}
 (@option{-N}) option on the command line, or else be
 prepared to parse the escaped names.
 
-The @option{--dired} (@option{-D}) option has well-defined behavior
-only when long format is in effect and hyperlinks are disabled (e.g.,
-@option{--hyperlink=none}).
+The @option{--dired} (@option{-D}) option implies long format output
+with hyperlinks disabled, and takes precedence over previously specified
+output formats or hyperlink mode.
 
 @item --full-time
 @opindex --full-time
index 5fe6e272554424ae83e9b32c1eaa9449714b83a3..dfb7718f742d3204c8dfab023b179a5506a43dfc 100644 (file)
--- a/src/ls.c
+++ b/src/ls.c
@@ -2054,6 +2054,8 @@ decode_switches (int argc, char **argv)
           break;
 
         case 'D':
+          format_opt = long_format;
+          print_hyperlink = false;
           dired = true;
           break;
 
@@ -2377,9 +2379,8 @@ 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 implies --format=long (-l) and sans --hyperlink.
+     So ignore it if those overridden.  */
   dired &= (format == long_format) & !print_hyperlink;
 
   if (eolbyte < dired)
index 417d3b5940d6b1e99ca23e3edee2f09bfa38a090..c4361d5e2e27bde4e38db2f5e3c7e5ba0fd50f5b 100755 (executable)
 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
 print_ver_ ls
 
+
 # Check with constant positions
 mkdir dir || framework_failure_
 
-LC_MESSAGES=C ls -lR --dired dir > out || fail=1
 cat <<EOF > exp
   dir:
   total 0
 //SUBDIRED// 2 5
 //DIRED-OPTIONS// --quoting-style=literal
 EOF
-
-compare exp out || fail=1
+for opt in '-l' '' '--hyperlink' '-x'; do
+  LC_MESSAGES=C ls $opt -R --dired dir > out || fail=1
+  compare exp out || fail=1
+done
 
 
 # Check with varying positions (due to usernames etc.)