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 Tue, 28 Jul 2026 15:20:13 +0300 Eli Zaretskii <[email protected]> wrote: >> From: Stephen Berman <[email protected]> >> Cc: [email protected], [email protected], [email protected] >> Date: Tue, 28 Jul 2026 13:39:16 +0200 >> >> On Tue, 28 Jul 2026 14:03:51 +0300 Eli Zaretskii <[email protected]> wrote: >> >> > How should I test on Windows, given that my 'ls' is GNU 'ls' and that >> > by default 'ls' is not used on Windows? >> >> Hm, I thought, evidently mistakenly, that any `ls' program did not work >> on MS-Windows and that's why ls-lisp is used for Dired there. > > That's the default, yes. But MS-Windows ports of GNU 'ls' do exist, > and I have such a port. So I can use it if necessary for this > testing. > >> > Also, Windows doesn't allow >> > file names with embedded newlines. So what and how should I test? >> >> Now I'm not sure; if your Windows uses GNU `ls' what happens if you try >> to visit in Dired a directory listing a file name containing a newline, > > There cannot be such file names on Windows, because Windows > filesystems don't allow that. Oops, you wrote that and I responded as if file names in Windows could have newlines; sorry for being so inattentive. So now I agree the changes to dired.el in the patch (checking for ls support of --dired instead of -b) are ok as is and there's nothing there that could be a problem in MS-Windows, even if it uses GNU `ls'. >> > The patch LGTM otherwise. >> >> I'm not sure about that either: in the tests I removed `(skip-when (memq >> system-type '(windows-nt ms-dos)))' because I thought `(skip-unless >> (dired--check-use-ls-dired))' would also skip the tests under Windows, >> but if GNU `ls' can be used there, I guess that wouldn't suffice and the >> skip-when sexp has to be restored? And `dired--toggle-b-switch' and the >> code in `dired-internal-noselect' for displaying the warning about file >> names with newlines would have to explicitly exclude windows-nt and >> ms-dos? > > You can check whether 'ls' is being used by testing > ls-lisp-use-insert-directory-program: its default is nil, but if the > user wants to use a ported 'ls', they can customize it to a non-nil > value. The tests should be skipped on MS-Windows (and MS-DOS) because they assume file names can have newlines. So just checking for an `ls' that supports --dired is not good enough (since GNU ls can be used on these platforms) and `(skip-when (memq system-type '(windows-nt ms-dos)))' must be restored. The corrected patch is attached. I'm confident that with the patch the tests will be skipped on Solaris and Alpine, so if Paul and John don't confirm in a day or two I'll go ahead and install it in emacs-31. Steve Berman
(unnamed)
(text/x-patch, 4 KB)
diff --git a/lisp/dired.el b/lisp/dired.el
index 1b88f2eab36..61d27919c51 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -1504,7 +1504,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))
@@ -1794,6 +1797,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.
@@ -1813,11 +1820,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.")
@@ -4078,10 +4081,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
@@ -4116,7 +4115,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..11e401fafa2 100644
--- a/test/lisp/dired-tests.el
+++ b/test/lisp/dired-tests.el
@@ -663,7 +663,9 @@ dired-test-filename-with-newline-1
;; 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)))
@@ -699,7 +701,9 @@ dired-test-filename-with-newline-2
;; 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)))