Project

General

Profile

Actions

Bug #19042

closed

Bug: Dir.glob ignores subdirectories in alternation when alternation is preceded by recursive directory pattern

Added by matthew.kern2 (Matt Kern) over 1 year ago. Updated over 1 year ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:110220]

Description

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:

➜  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


Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #13167: Dir.glob is 25x slower since Ruby 2.2Closedh.shirosaki (Hiroshi Shirosaki)Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0