Backport #8283

Dir.glob doesn't recurse hidden directories

Added by Gregory Pakosz about 2 years ago. Updated about 2 years ago.

[ruby-core:54387]
Status:Closed
Priority:Normal
Assignee:Tomoyuki Chikanaga

Description

Hello,

I noticed Dir.glob('**') doesn't recurse hidden directories.

I believe regression has been introduced by r36903.

Here is the following directory / file structure:
$ find .
.
./foo
./foo/.bar
./foo/.bar/baz.txt
./foo/bar

And here is the behavior of ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin11.4.2]:
$ ruby -e "puts Dir.glob('*/')"
foo
foo/bar

Associated revisions

Revision 40345
Added by Nobuyoshi Nakada about 2 years ago

dir.c: not skip dot directories if matching

  • dir.c (glob_helper): should skip dot directories only for recursion, but should not if matching to the given pattern. [Bug #8283]

Revision 40394
Added by Tomoyuki Chikanaga about 2 years ago

merge revision(s) 40345: [Backport #8283]

* dir.c (glob_helper): should skip dot directories only for recursion,
  but should not if matching to the given pattern.  
  [Bug #8283]

History

#1 Updated by Nobuyoshi Nakada about 2 years ago

  • Status changed from Open to Rejected

$ /usr/bin/ruby -v -e 'puts Dir.glob("*/")'
ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin11.0]
foo
foo/bar

#2 Updated by Gregory Pakosz about 2 years ago

well actually behavior changed between ruby 1.9.3-p392 and ruby 2.0.0-p0

I have a script that does:

local_repositories = []
Dir['all/**/.git/config'].each do |f|
config = IniFile.load(f)
url = config['remote "origin"']['url']
local
repositories << (url.end_with?('.git') ? url : "#{url}.git")
end

and that broke when upgrading to ruby 2.0.0-p0
with ruby 2.0.0-p0, Dir.glob doesn't enter .git directories at all
I had to change the expression to Dir['_all/*/.git/config']

so there is indeed a behavior change between ruby 1.9.3-p392 and ruby 2.0.0-p0, other people confirmed on their boxes on #ruby freenode

can you please reconsider the rejection?
thank you

#3 Updated by Nobuyoshi Nakada about 2 years ago

  • Status changed from Rejected to Assigned
  • Assignee set to Nobuyoshi Nakada

OK, that example makes sense.

#4 Updated by Nobuyoshi Nakada about 2 years ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r40345.
Gregory, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


dir.c: not skip dot directories if matching

  • dir.c (glob_helper): should skip dot directories only for recursion, but should not if matching to the given pattern. [Bug #8283]

#5 Updated by Nobuyoshi Nakada about 2 years ago

  • Tracker changed from Bug to Backport
  • Project changed from Ruby trunk to Backport200
  • Category deleted (core)
  • Status changed from Closed to Assigned
  • Assignee changed from Nobuyoshi Nakada to Tomoyuki Chikanaga

#6 Updated by Hans Mackowiak about 2 years ago

moment ... i thought thats FNM_DOTMATCH for so glob("") does not include the .git dir, but glob("",File::FNM_DOTMATCH) does ... i thought this was a feature and not a bug

#7 Updated by Tomoyuki Chikanaga about 2 years ago

Hello, Hans.

After r40345, the result of Dir.glob("") don't change, but Dir.glob("/.git/config") matches "./.git/config" or so, and it is consistent with shell's behavior.
I think r40345 is appropriate bugfix.

#8 Updated by Tomoyuki Chikanaga about 2 years ago

  • Status changed from Assigned to Closed

This issue was solved with changeset r40394.
Gregory, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


merge revision(s) 40345: [Backport #8283]

* dir.c (glob_helper): should skip dot directories only for recursion,
  but should not if matching to the given pattern.  
  [Bug #8283]

Also available in: Atom PDF