Subject: bug#71235: Failing test on macOS: tramp-test17-dired-with-wildcards

From: Michael Albinus <[email-masked]>
Date: Thu, 30 May 2024 14:12:48 +0200

Stefan Kangas <[email-masked]> writes:

Hi Stefan,

>>> I see one tramp test fail on macOS 14.3.1.  Details below:
>>>
>>> Ran 98 tests, 82 results as expected, 1 unexpected, 15 skipped
>>> (2024-05-27 23:27:48+0200, 89.934240 sec)
>>>
>>> 1 unexpected results:
>>>    FAILED  tramp-test17-dired-with-wildcards
>>
>> Could you pls instrument the test, and run it again? See appended patch.
>
> I've sent you the logs off-list.

Thanks for this. The problem is obvious in the log:

--8<---------------cut here---------------start------------->8---
00:52:56.390327 tramp-send-command (6) # ( cd /var/folders/28/y4qn6tl11_126568wmx_6kpr0000gn/T/ && env INSIDE_EMACS\=30.0.50\,tramp\:2.7.1-pre /bin/sh -c gls\ -d\ -al\ tramp-test\*/\* </dev/null; echo tramp_exit_status $? )
00:52:56.394295 tramp-wait-for-regexp (6) # 
/bin/sh: gls: command not found
tramp_exit_status 127
///75ffbd7d44c24c99d4107a0eba33363e#$
--8<---------------cut here---------------end--------------->8---

However, Tramp hasn't decided to use gls on its own. Debugging the test
case, it looks like it comes from dired-insert-directory:

--8<---------------cut here---------------start------------->8---
    ;; Expand directory wildcards and fill file-list.
    (let ((dir-wildcard (and (null file-list) wildcard
                             (insert-directory-wildcard-in-dir-p dir))))
      (cond ((and dir-wildcard (files--use-insert-directory-program-p))
             (setq switches (concat "-d " switches))
             (let* ((default-directory (car dir-wildcard))
                    (script (format "%s %s %s"
                                    insert-directory-program
                                    switches (cdr dir-wildcard)))
                    (sh (or (and remotep "/bin/sh")
                            (executable-find shell-file-name)
                            (executable-find "sh")))
                    (switch (if remotep "-c" shell-command-switch)))
               ;; Enable globstar
               (when-let ((globstar dired-maybe-use-globstar)
                          (enable-it
                           (assoc-default
                            (file-truename sh) dired-enable-globstar-in-shell
                            (lambda (reg shell) (string-match reg shell)))))
                 (setq script (format "%s; %s" enable-it script)))
               (unless
                   (zerop
                    (process-file sh nil (current-buffer) nil switch script))
                 (user-error
                  "%s: No files matching wildcard" (cdr dir-wildcard)))
               (insert-directory-clean (point) switches)))
--8<---------------cut here---------------end--------------->8---

'script' is a formatted string, which includes
'insert-directory-program'. And that user option tells us

--8<---------------cut here---------------start------------->8---
Absolute or relative name of the ‘ls’-like program.
This is used by ‘insert-directory’ and ‘dired-insert-directory’
(thus, also by ‘dired’).  For Dired, this should ideally point to
GNU ls, or another version of ls that supports the "--dired"
flag.  See ‘dired-use-ls-dired’.

On GNU/Linux and other capable systems, the default is "ls".

On *BSD and macOS systems, the default "ls" does not support
the "--dired" flag.  Therefore, the default is to use the
"gls" executable on such machines, if it exists.  This means
that there should normally be no need to customize this when
installing GNU coreutils using something like ports or Homebrew.
--8<---------------cut here---------------end--------------->8---

So I guess 'insert-directory-program' is "gls" in your case, but Tramp
doesn't find it. Where is it installed? What does '(executable-find "gls")'
return on your machine?

Best regards, Michael.