From: "matthew.kern2 (Matt Kern)" Date: 2022-10-06T19:39:00+00:00 Subject: [ruby-core:110220] [Ruby master Bug#19042] Bug: Dir.glob ignores subdirectories in alternation when alternation is preceded by recursive directory pattern Issue #19042 has been reported by matthew.kern2 (Matt Kern). ---------------------------------------- Bug #19042: Bug: Dir.glob ignores subdirectories in alternation when alternation is preceded by recursive directory pattern https://bugs.ruby-lang.org/issues/19042 * Author: matthew.kern2 (Matt Kern) * Status: Open * Priority: Normal * ruby -v: 2.7.2 * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN ---------------------------------------- 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: