mvdan / sh

A shell parser, formatter, and interpreter with bash support; includes shfmt
https://pkg.go.dev/mvdan.cc/sh/v3
BSD 3-Clause "New" or "Revised" License
7.27k stars 345 forks source link

expand: globstar expansion can return errors or leave leading spaces #829

Closed theclapp closed 2 years ago

theclapp commented 2 years ago
% gosh
$ pwd
/Users/lmc
$ shopt
expand_aliases  off
globstar    off
nullglob    off
$ echo **
lots of files
$ shopt -s globstar
$ echo **
fdopendir: not a directory

On macOS, in case it matters (and wasn't obvious from the PWD :).

theclapp commented 2 years ago

Also, it doesn't like sockets. Could be the same bug, though.

% gosh
$ pwd
/tmp
$ ls -la
total 0
drwxrwxrwt 10 root wheel 320 Mar 22 08:32 .
drwxr-xr-x  6 root wheel 192 Jan  1  2020 ..
drwx------  3 lmc  wheel  96 Feb  8 09:12 .vbox-lmc-ipc
drwx------  3 lmc  wheel  96 Jan 18 08:59 com.apple.launchd.MaQaVePSF0
drwx------  3 lmc  wheel  96 Jan 18 08:59 com.apple.launchd.Mkn79cVqM0
drwxr-xr-x  2 lmc  wheel  64 Mar 19 13:01 com.google.Keystone
drwxr-xr-x  2 lmc  wheel  64 Mar 19 13:01 dir
srw-------  1 lmc  wheel   0 Mar 19 16:16 drivefs_ipc.501
srw-------  1 lmc  wheel   0 Mar 19 16:16 drivefs_ipc.501_shell
drwxr-xr-x  2 root wheel  64 Mar 20 12:26 powerlog
$ echo **
com.apple.launchd.MaQaVePSF0 com.apple.launchd.Mkn79cVqM0 com.google.Keystone dir drivefs_ipc.501 drivefs_ipc.501_shell powerlog
$ shopt -s globstar
$ echo **
open /tmp/drivefs_ipc.501: operation not supported on socket
mvdan commented 2 years ago

Hmm, is this a recent regression? It could be caused by my trick to use ReadDir instead of Stat for globbing.

theclapp commented 2 years ago

Dunno. Haven't played with globbing much. I'm working on completion in my gui shell so now it's coming up a lot more. :)

echo **/ seems to work, though it prepends a space?

% gosh
$ pwd
/tmp
$ shopt -s globstar
$ ls -la
total 0
drwxrwxrwt 10 root wheel 320 Mar 22 08:32 .
drwxr-xr-x  6 root wheel 192 Jan  1  2020 ..
drwx------  3 lmc  wheel  96 Feb  8 09:12 .vbox-lmc-ipc
drwx------  3 lmc  wheel  96 Jan 18 08:59 com.apple.launchd.MaQaVePSF0
drwx------  3 lmc  wheel  96 Jan 18 08:59 com.apple.launchd.Mkn79cVqM0
drwxr-xr-x  2 lmc  wheel  64 Mar 19 13:01 com.google.Keystone
drwxr-xr-x  2 lmc  wheel  64 Mar 19 13:01 dir
srw-------  1 lmc  wheel   0 Mar 19 16:16 drivefs_ipc.501
srw-------  1 lmc  wheel   0 Mar 19 16:16 drivefs_ipc.501_shell
drwxr-xr-x  2 root wheel  64 Mar 20 12:26 powerlog
$ echo **/
 com.apple.launchd.MaQaVePSF0/ com.apple.launchd.Mkn79cVqM0/ com.google.Keystone/ dir/ powerlog/
$
mvdan commented 2 years ago

Thanks, I can easily reproduce both failures. The good news is that this is not a regression; I get exactly the same failures if I revert the recent change to replace Stat with ReadDir.