Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
theclapp opened this issue Mar 22, 2022 · 4 comments · Fixed by #834
Closed

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

theclapp opened this issue Mar 22, 2022 · 4 comments · Fixed by #834

Comments

@theclapp
Copy link
Collaborator

% 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
Copy link
Collaborator Author

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
Copy link
Owner

mvdan commented Mar 22, 2022

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

@theclapp
Copy link
Collaborator Author

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
Copy link
Owner

mvdan commented Mar 29, 2022

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.

@mvdan mvdan changed the title interp: "echo **" with globstar set returns an error expand: globstar expansion can return errors or leave leading spaces Mar 29, 2022
mvdan added a commit that referenced this issue Mar 29, 2022
The previous globstar implementation was breadth-first search,
whereas Bash implements depth-first search.

Moreover, when recursing into directories, we could stop early and give
an error to the user when encountering a non-directory.
Instead, we want to simply not recurse into that path.

Add tests for both cases, too.

Fixes #829.
mvdan added a commit that referenced this issue Mar 29, 2022
The previous globstar implementation was breadth-first search,
whereas Bash implements depth-first search.

Moreover, when recursing into directories, we could stop early and give
an error to the user when encountering a non-directory.
Instead, we want to simply not recurse into that path.

Add tests for both cases, too.

Fixes #829.
mvdan added a commit that referenced this issue Mar 29, 2022
The previous globstar implementation was breadth-first search,
whereas Bash implements depth-first search.

Moreover, when recursing into directories, we could stop early and give
an error to the user when encountering a non-directory.
Instead, we want to simply not recurse into that path.

Add tests for both cases, too.

Fixes #829.
mvdan added a commit that referenced this issue Mar 31, 2022
The previous globstar implementation was breadth-first search,
whereas Bash implements depth-first search.

Moreover, when recursing into directories, we could stop early and give
an error to the user when encountering a non-directory.
Instead, we want to simply not recurse into that path.

Add tests for both cases, too.

Fixes #829.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants