Skip to content

Ruby Dir.glob bug

To further elaborate on Yehuda’s twit:

[~/tmp][rando@apollo]
 % mkdir first first/second
[~/tmp][rando@apollo]
 % touch first/second/test.txt
[~/tmp][rando@apollo]
 % chmod -x first
[~/tmp][rando@apollo]
 % ls first/second/*.txt
ls: cannot access first/second/*.txt: Permission denied
[~/tmp][rando@apollo]
 % irb
irb(main):001:0> Dir.glob('first/second/*.txt')
=> []

If you try to glob some things in a directory that has some ancestor missing the eXecute permission, ruby doesn’t give any indication of an error.

This took Yehuda and I about 30 minutes to track down why a merb app wasn’t loading bundled gems under passenger. Apache was running as nobody, and the parent dir of the app was missing the global execute permission.

{ 2 } Comments

  1. Michael Ivey | January 20, 2009 at 8:08 pm | Permalink

    What would you expect it to do? From Ruby’s perspective, those files do not exist.

    Dir["foo/bar/*"] where foo does not exist also returns []. It’s the same thing.

  2. Paul Sadauskas | February 3, 2009 at 12:38 pm | Permalink

    I would expect it to raise an error, just like ls did, not silently pretend that nothings wrong.

    This exact bug caused me 6 hours of pain last week, because rubygems couldn’t load any gems in a dir that was a great-grandchild of a dir that wasn’t world-executable.

Post a Comment

Your email is never published nor shared. Required fields are marked *