[prev in list] [next in list] [prev in thread] [next in thread]
List: ruby-core
Subject: [ruby-core:110490] [Ruby master Bug#19042] Bug: Dir.glob ignores subdirectories in alternation when
From: "nagachika (Tomoyuki Chikanaga)" <noreply () ruby-lang ! org>
Date: 2022-10-23 10:42:22
Message-ID: redmine.journal-99811.20221023104222.52504 () ruby-lang ! org
[Download RAW message or body]
Issue #19042 has been updated by nagachika (Tomoyuki Chikanaga).
Backport changed from 2.7: REQUIRED, 3.0: REQUIRED, 3.1: REQUIRED to 2.7: REQUIRED, \
3.0: REQUIRED, 3.1: DONE
ruby_3_1 ffa439fd29141626878f4c4b56e86b2fee17294e merged revision(s) \
329d5424a479bb08e75bd750c51a5382e382731c.
----------------------------------------
Bug #19042: Bug: Dir.glob ignores subdirectories in alternation when alternation is \
preceded by recursive directory pattern \
https://bugs.ruby-lang.org/issues/19042#change-99811
* Author: matthew.kern2 (Matt Kern)
* Status: Closed
* Priority: Normal
* ruby -v: 2.7.2
* Backport: 2.7: REQUIRED, 3.0: REQUIRED, 3.1: DONE
----------------------------------------
The Dir.glob method omits results from subdirectories listed in an alternation when \
that alternation is preceded by a recursive directory pattern (`**/`).
Demonstration here: https://replit.com/@MattKern1/Dirglob-subdirectory-alternation-issue?v=1
I have reproduced this in `ruby 2.7.2` and `ruby 3.0.0`.
Local output:
``` shell
➜ tree
.
└── tmp
├── dir_a
│ └── file_a1.txt
└── dir_b
└── subdir
└── file_b1.txt
4 directories, 2 files
➜ irb
2.7.2 :001 > Dir.glob('tmp/{dir_a,dir_b/subdir}/*.txt')
=> ["tmp/dir_a/file_a1.txt", "tmp/dir_b/subdir/file_b1.txt"]
2.7.2 :002 > Dir.glob('**/{dir_a,dir_b/subdir}/*.txt')
=> ["tmp/dir_a/file_a1.txt"]
2.7.2 :003 > exit
```
You can see that while the text file in `dir_a` shows up in both examples, the text \
file in `dir_b/subdir` shows up when the preceding path is explicitly defined, but \
not when `tmp/` is replaced with the more general recursive directory expression \
`**/`.
Works properly with ruby 2.5.3
```
2.5.3 :001 > Dir.glob('tmp/{dir_a,dir_b/subdir}/*.txt')
=> ["tmp/dir_a/file_a1.txt", "tmp/dir_b/subdir/file_b1.txt"]
2.5.3 :002 > Dir.glob('**/{dir_a,dir_b/subdir}/*.txt')
=> ["tmp/dir_a/file_a1.txt", "tmp/dir_b/subdir/file_b1.txt"]
```
This seems related to this line of code: \
https://github.com/ruby/ruby/blob/7b413c1db3e65909c6899e1d3be4d16c3e76149c/dir.c#L2140
I'm not sure exactly what changed between version 2.5.3 and 2.7.2, but there do \
appear to be some significant code changes (and the order of results from Dir.glob is \
sometimes different). Possibly related to this discussion? \
https://bugs.ruby-lang.org/issues/17280
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic