* [ruby-core:100525] [Ruby master Bug#17283] Why does Dir.glob's ** match files in current directory?
@ 2020-10-24 19:57 tyanir
2020-10-25 12:23 ` [ruby-core:100526] " eregontp
2020-10-25 13:14 ` [ruby-core:100530] " nobu
0 siblings, 2 replies; 3+ messages in thread
From: tyanir @ 2020-10-24 19:57 UTC (permalink / raw)
To: ruby-core
Issue #17283 has been reported by Yanir (Yanir Name).
----------------------------------------
Bug #17283: Why does Dir.glob's ** match files in current directory?
https://bugs.ruby-lang.org/issues/17283
* Author: Yanir (Yanir Name)
* Status: Open
* Priority: Normal
* ruby -v: ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x64-mingw32]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
If my current directory has 1 file and 1 dir, and I use `Dir.glob("**/*")` or even just `**`, both the dir and the file would be matched.
I would expect that only the dir will be matched, since the glob starts with `**`, which wants to match a directory.
This is a behavior that's different from bash. In bash only the directory would be matched.
Ruby:
```
Directory of C:\Users\User\z
10/24/2020 10:42 PM <DIR> .
10/24/2020 10:42 PM <DIR> ..
10/24/2020 10:42 PM <DIR> dir
10/24/2020 10:41 PM 4 file
1 File(s) 4 bytes
3 Dir(s) 256,993,574,912 bytes free
C:\Users\User\z>irb
irb(main):001:0> Dir.glob("**/*")
=> ["dir", "file"]
irb(main):002:0> Dir.glob("**")
=> ["dir", "file"]
```
In Bash:
```
root@debian:~/rubytest# ls -lah
total 12K
drwxr-xr-x 3 root root 4.0K Oct 23 17:44 .
drwx------ 19 root root 4.0K Oct 23 17:43 ..
drwxr-xr-x 2 root root 4.0K Oct 23 17:44 dir
-rw-r--r-- 1 root root 0 Oct 23 17:44 file
root@debian:~/rubytest# ls -lah **/*
-rw-r--r-- 1 root root 0 Oct 23 17:44 dir/subfile
```
**I know the behavior is not meant to be 1:1 to bash**. But this is still unexpected and doesn't make sense to me. Is this intended?
The documentation says:
```
**
Matches directories recursively.
```
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 3+ messages in thread
* [ruby-core:100526] [Ruby master Bug#17283] Why does Dir.glob's ** match files in current directory?
2020-10-24 19:57 [ruby-core:100525] [Ruby master Bug#17283] Why does Dir.glob's ** match files in current directory? tyanir
@ 2020-10-25 12:23 ` eregontp
2020-10-25 13:14 ` [ruby-core:100530] " nobu
1 sibling, 0 replies; 3+ messages in thread
From: eregontp @ 2020-10-25 12:23 UTC (permalink / raw)
To: ruby-core
Issue #17283 has been updated by Eregon (Benoit Daloze).
Interestingly this behavior differs between Bash and Zsh:
```
$ tree
.
├── dir
│ └── subfile
└── foo
$ bash
$ echo **/*
dir/subfile
$ zsh -f
$ echo **/*
dir dir/subfile foo
```
I think we cannot change the behavior for compatibility.
As a fun fact, `"**"` can even match the parent directory with `FNM_DOTMATCH` (#17280).
----------------------------------------
Bug #17283: Why does Dir.glob's ** match files in current directory?
https://bugs.ruby-lang.org/issues/17283#change-88149
* Author: Yanir (Yanir Name)
* Status: Open
* Priority: Normal
* ruby -v: ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x64-mingw32]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
If my current directory has 1 file and 1 dir, and I use `Dir.glob("**/*")` or even just `**`, both the dir and the file would be matched.
I would expect that only the dir will be matched, since the glob starts with `**`, which wants to match a directory.
This is a behavior that's different from bash. In bash only the directory would be matched.
Ruby:
```
Directory of C:\Users\User\z
10/24/2020 10:42 PM <DIR> .
10/24/2020 10:42 PM <DIR> ..
10/24/2020 10:42 PM <DIR> dir
10/24/2020 10:41 PM 4 file
1 File(s) 4 bytes
3 Dir(s) 256,993,574,912 bytes free
C:\Users\User\z>irb
irb(main):001:0> Dir.glob("**/*")
=> ["dir", "file"]
irb(main):002:0> Dir.glob("**")
=> ["dir", "file"]
```
In Bash:
```
root@debian:~/rubytest# ls -lah
total 12K
drwxr-xr-x 3 root root 4.0K Oct 23 17:44 .
drwx------ 19 root root 4.0K Oct 23 17:43 ..
drwxr-xr-x 2 root root 4.0K Oct 23 17:44 dir
-rw-r--r-- 1 root root 0 Oct 23 17:44 file
root@debian:~/rubytest# ls -lah **/*
-rw-r--r-- 1 root root 0 Oct 23 17:44 dir/subfile
```
**I know the behavior is not meant to be 1:1 to bash**. But this is still unexpected and doesn't make sense to me. Is this intended?
The documentation says:
```
**
Matches directories recursively.
```
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 3+ messages in thread
* [ruby-core:100530] [Ruby master Bug#17283] Why does Dir.glob's ** match files in current directory?
2020-10-24 19:57 [ruby-core:100525] [Ruby master Bug#17283] Why does Dir.glob's ** match files in current directory? tyanir
2020-10-25 12:23 ` [ruby-core:100526] " eregontp
@ 2020-10-25 13:14 ` nobu
1 sibling, 0 replies; 3+ messages in thread
From: nobu @ 2020-10-25 13:14 UTC (permalink / raw)
To: ruby-core
Issue #17283 has been updated by nobu (Nobuyoshi Nakada).
Eregon (Benoit Daloze) wrote in #note-2:
> Interestingly this behavior differs between Bash and Zsh:
Bash **doesn't** support `**`, and it just equals `*`.
----------------------------------------
Bug #17283: Why does Dir.glob's ** match files in current directory?
https://bugs.ruby-lang.org/issues/17283#change-88154
* Author: Yanir (Yanir Name)
* Status: Closed
* Priority: Normal
* ruby -v: ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x64-mingw32]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
If my current directory has 1 file and 1 dir, and I use `Dir.glob("**/*")` or even just `**`, both the dir and the file would be matched.
I would expect that only the dir will be matched, since the glob starts with `**`, which wants to match a directory.
This is a behavior that's different from bash. In bash only the directory would be matched.
Ruby:
```
Directory of C:\Users\User\z
10/24/2020 10:42 PM <DIR> .
10/24/2020 10:42 PM <DIR> ..
10/24/2020 10:42 PM <DIR> dir
10/24/2020 10:41 PM 4 file
1 File(s) 4 bytes
3 Dir(s) 256,993,574,912 bytes free
C:\Users\User\z>irb
irb(main):001:0> Dir.glob("**/*")
=> ["dir", "file"]
irb(main):002:0> Dir.glob("**")
=> ["dir", "file"]
```
In Bash:
```
root@debian:~/rubytest# ls -lah
total 12K
drwxr-xr-x 3 root root 4.0K Oct 23 17:44 .
drwx------ 19 root root 4.0K Oct 23 17:43 ..
drwxr-xr-x 2 root root 4.0K Oct 23 17:44 dir
-rw-r--r-- 1 root root 0 Oct 23 17:44 file
root@debian:~/rubytest# ls -lah **/*
-rw-r--r-- 1 root root 0 Oct 23 17:44 dir/subfile
```
**I know the behavior is not meant to be 1:1 to bash**. But this is still unexpected and doesn't make sense to me. Is this intended?
The documentation says:
```
**
Matches directories recursively.
```
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-10-25 13:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-24 19:57 [ruby-core:100525] [Ruby master Bug#17283] Why does Dir.glob's ** match files in current directory? tyanir
2020-10-25 12:23 ` [ruby-core:100526] " eregontp
2020-10-25 13:14 ` [ruby-core:100530] " nobu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).