bug#81481: 31.0.91; dired-test-filename-with-newline failures on 32-bit Solaris sparc
Stephen Berman via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <[email protected]>
| Newsgroups | gmane.emacs.bugs |
|---|---|
| Message-ID | <[email protected]> |
On Mon, 27 Jul 2026 00:42:06 +0200 Stephen Berman <[email protected]> wrote: > On Sun, 26 Jul 2026 10:45:53 -0700 Paul Eggert <[email protected]> wrote: > >> On 2026-07-26 02:17, Stephen Berman wrote: >> >>> files, if you visit the directory in Dired, move with `n' to the entry >>> `a b' (so the cursor is on "a") and evaluate >>> `(dired-move-to-end-of-filename)', where is point now? I'd guess >>> between "a" and the space. >> >> No, it's after the 'b'. >> >> However, it is indeed after the 'a' for the file name that is 'a' followed by >> newline followed by 'b'. >> >>>If instead point is after "b" (as it is with> GNU `ls'), then I have no idea >> why the search fails. >> >> Without looking at the Emacs code I can intuitively see why it works for 'a b' >> but not for 'a' newline 'b'. In the former, there's no other way to interpret >> the line. In the latter there is. > > Oops, I had blinders on before: when I looked at the test code after > seeing your report I was only paying attention to the fact that > searching backward for a string containing a space fails, but ignoring > where point is when `search-backward' was called, namely, where > `dired-move-to-end-of-filename' put it, which, on Solaris where `ls' > lacks the --dired switch, is just before the newline in the filename, as > you have just confirmed. But in the test the part of the file name with > the space is after the newline, so of course the search fails! > >>> If you run just `dired-test-filename-with-newline-1' on >>> Solaris in a fresh Emacs session where Dired has not yet been used, I >>> would expect you to see this message. >> >> Yes, I see the message "ls does not support --dired -N; see >> `dired-use-ls-dired' for more details.". If I then visit a directory >> containing an entry that has a newline a *Warnings* buffer appears that says >> the following: >> >> Warning (dired): Literal newline in file name. >> This Dired buffer displays a file name containing a literal newline character. >> Executing Dired operations on files displayed this way may fail and signal an >> error. To avoid this you can temporarily change the display for all Dired >> buffers, so that newlines in file names appear as "\n", by typing `M-:' and >> entering `(setopt dired-auto-toggle-b-switch t)' in the minibuffer. To change >> the display only for this Dired buffer click or press RETURN `here'. See >> `(emacs) Dired Enter' for other alternatives and more information. > > Right, this is because the test for whether a file name in a directory > contains a newline uses the primitive function `directory-files'; how > Dired (or `ls') displays file names plays no role in that test. > However, displaying the warning also depends on Dired using an `ls' that > supports the -b switch. This condition was added in abde2d1ed3b due to > a report of the same Dired tests failing as you have reported; but in > that case, the `ls' used by Dired supported neither --dired nor -b, and > I concluded that only testing for -b support was sufficient > (https://debbugs.gnu.org/cgi/bugreport.cgi?bug=80499#190). But your > report shows that conclusion was mistaken. Moreover, what the above > warning says to do to avoid problems in Dired with a literal newline in > a file name does not work on Solaris, since -b there does not do what -b > in GNU `ls' does; so showing the warning in Solaris is not really > appropriate. > >>> If so, then skipping the test on >>> Solaris would be appropriate. > > I think this is correct, but I think the fix, both for the test failures > and for deciding whether to display the warning and suggest changing the > the Dired display, is to use `dired-use-ls-dired', as was considered > earlier on in that other bug report > (https://debbugs.gnu.org/cgi/bugreport.cgi?bug=80499#145), instead > testing for ls support of -b. I'll post a patch later. The patch is attached. If I made no mistake, the tests dired-test-filename-with-newline-1 and dired-test-filename-with-newline-2 should now be skipped on platforms using an `ls' that does not support the --dired switch, and on such platforms no warning should be displayed when visiting in Dired a directory listing a file name containing a newline with `dired-auto-toggle-b-switch' set to nil (the default), and setting this user option to t should have no effect on such platforms. Paul, can you confirm for Solaris, and John Muhl (Cc'd), can you confirm for Alpine, and Eli, can you confirm for MS-Windows? (On platforms with an `ls' that supports --dired, the behavior with the patch should be unchanged from the behavior with the current code; I've confirmed this for my GNU/Linux system.) Eli, if you, Paul and John confirm as requested, can this patch go into emacs-31? The bug report of the test failures was against emacs-31, and the the only substantive change is that where previously we tested whether `ls' supports a -b switch, now with the patch we test whether `ls' supports the --dired switch. Steve Berman
(unnamed)
(text/x-patch, 4.3 KB)
diff --git a/lisp/dired.el b/lisp/dired.el
index 53ec6779061..237d4bbd69b 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -1492,7 +1492,10 @@ dired-internal-noselect
(dired-switches-escape-p dired-listing-switches)
(dired-switches-escape-p dired-actual-switches))
(when (and (dired--filename-with-newline-p)
- (dired--ls-accept-b-switch-p))
+ ;; Can't use `dired-use-ls-dired' because users could
+ ;; set it to `t' even though their `ls' does not
+ ;; support "--dired".
+ (dired--check-use-ls-dired))
(dired--display-filename-with-newline-warning buffer)))
(set-buffer old-buf)
buffer))
@@ -1782,6 +1785,10 @@ dired-switches-recursive-p
"Return non-nil if the string SWITCHES contains -R or --recursive."
(dired-check-switches switches "R" "recursive"))
+(defun dired--check-use-ls-dired ()
+ "Return non-nil if `ls' supports the \"--dired\" switch."
+ (eq 0 (call-process insert-directory-program nil nil nil "--dired" "-N")))
+
(defun dired-insert-directory (dir switches &optional file-list wildcard hdr)
"Insert a directory listing of DIR, Dired style.
Use SWITCHES to make the listings.
@@ -1801,11 +1808,7 @@ dired-insert-directory
(not (bound-and-true-p eshell-ls-use-in-dired))
(or remotep
(if (eq dired-use-ls-dired 'unspecified)
- ;; Check whether "ls --dired" gives exit code 0, and
- ;; save the answer in `dired-use-ls-dired'.
- (or (setq dired-use-ls-dired
- (eq 0 (call-process insert-directory-program
- nil nil nil "--dired" "-N")))
+ (or (setq dired-use-ls-dired (dired--check-use-ls-dired))
(progn
(message "ls does not support --dired -N; \
see `dired-use-ls-dired' for more details.")
@@ -4066,10 +4069,6 @@ dired--filename-with-newline-p
a literal newline or as \"\\n\")."
(directory-files default-directory nil "\n"))
-(defun dired--ls-accept-b-switch-p ()
- "Return non-nil if the `ls' used by Dired accepts the `b' switch."
- (eq 0 (call-process insert-directory-program nil nil nil "-b")))
-
(defun dired--remove-b-switch ()
"Remove all variants of the `b' switch from `dired-actual-switches'.
This removes not only all occurrences of the short form `-b' but also
@@ -4104,7 +4103,10 @@ dired--toggle-b-switch
(defun dired--set-auto-toggle-b-switch (symbol value)
"The :set function for user option `dired-auto-toggle-b-switch'."
(custom-set-default symbol value)
- (when (dired--ls-accept-b-switch-p)
+ (when
+ ;; Can't use `dired-use-ls-dired' because users could set it to
+ ;; `t' even though their `ls' does not support "--dired".
+ (dired--check-use-ls-dired)
(if value
(add-hook 'post-command-hook #'dired--toggle-b-switch nil t)
(remove-hook 'post-command-hook #'dired--toggle-b-switch t))
diff --git a/test/lisp/dired-tests.el b/test/lisp/dired-tests.el
index 65ca58cc705..47ead6a30b3 100644
--- a/test/lisp/dired-tests.el
+++ b/test/lisp/dired-tests.el
@@ -660,10 +660,9 @@ dired-test-hide-absolute-location-disabled
(ert-deftest dired-test-filename-with-newline-1 () ; bug#79528, bug#80499
"Test handling of file name with literal embedded newline."
- ;; File names with embedded newlines are not allowed on MS-Windows and
- ;; MS-DOS.
- (skip-when (memq system-type '(windows-nt ms-dos)))
- (skip-unless (dired--ls-accept-b-switch-p))
+ ;; The handling of file names with embedded newlines requires an `ls'
+ ;; that supports the "--dired" switch.
+ (skip-unless (dired--check-use-ls-dired))
(with-current-buffer "*Messages*"
(let ((inhibit-read-only t))
(erase-buffer)))
@@ -696,10 +695,9 @@ dired-test-filename-with-newline-1
(ert-deftest dired-test-filename-with-newline-2 () ; bug#79528, bug#80499
"Test handling of file name with embedded newline using `b' switch."
- ;; File names with embedded newlines are not allowed on MS-Windows and
- ;; MS-DOS.
- (skip-when (memq system-type '(windows-nt ms-dos)))
- (skip-unless (dired--ls-accept-b-switch-p))
+ ;; The handling of file names with embedded newlines requires an `ls'
+ ;; that supports the "--dired" switch.
+ (skip-unless (dired--check-use-ls-dired))
(with-current-buffer "*Messages*"
(let ((inhibit-read-only t))
(erase-buffer)))