Is this a Ruby bug in Dir on Windows?

W

Wayne Magor

This was discussed on another thread, but I thought I'd ask the question
here to see if this is a bug or if it should work this way.

This line doesn't seem work from the Windows root directory (C:\) but
works from a subdir.

ruby -e 'puts Dir.glob("/**/*.txt")' # Prints nothing


Here's some commentary from the other thread:

Why doesn't that seem to work for me on Windows? Is there something
different about it on Windows than on Linux?

Is there something different about being at the top-level directory on
Windows? It's unexpected behavior for me. Why does it operate like
that?

Looks like it behaves oddly at the root:
C:\>irb
irb(main):001:0> Dir.glob( './**/*.rb' ).length
=> 2
irb(main):002:0> Dir.chdir( 'c:/documents and settings/gavin.kistner/
desktop' )
=> 0
irb(main):003:0> Dir.glob( './**/*.rb' ).length
=> 638
irb(main):004:0> Dir.chdir( 'c:/' )
=> 0
irb(main):005:0> Dir.glob( './**/*.rb' ).length
=> 2
irb(main):006:0> Dir.glob( '.\\**\\*.rb' ).length
=> 0

Further evidence, showing that it's not an issue with ** not diving
more than a couple levels deep:


C:\tmp>irb
irb(main):001:0> Dir.glob( './**/*.rb' )
=> ["./l1/l1.rb", "./l1/l2/l2.rb", "./l1/l2/l3/l3.rb", "./l1/l2/l3/l4/
l4.rb"]
irb(main):002:0> Dir.chdir( '..' )
=> 0
irb(main):003:0> Dir.glob( './**/*.rb' )
=> ["./const_alias1.rb", "./const_alias2.rb"]
irb(main):004:0> Dir.glob( 'tmp/**/*.rb' )
=> ["tmp/l1/l1.rb", "tmp/l1/l2/l2.rb", "tmp/l1/l2/l3/l3.rb", "tmp/l1/
l2/l3/l4/l4.rb"]

Smells like a bug to me, but that's a dangerous claim for someone who
hasn't looked at the implementation. Certainly unexpected behavior by
me, too.
 
M

Michael Linfield

This is an educated guess, but i suspect it has to do with the way
Windows handles accounts. This program at root will try to go into
/documents and settings/administrator , when it trys to access this
folder Windows will deny the program access. So before it hits
administrator or some other folder that Windows wont allow ruby access
to, it may have found 2 .rb (ruby applications) files in say User
Documents.

- Mac
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,697
Latest member
AugustNabo

Latest Threads

Top