Truffleruby: Globbing with `FNM_DOTMATCH` misses some hidden files

Created on 6 Oct 2020  路  4Comments  路  Source: oracle/truffleruby

The following script prints bar/.baz/qux on CRuby, but nothing on truffleruby.

require 'tmpdir'

Dir.mktmpdir("foo") do |tmpdir|
  Dir.chdir(tmpdir) do
    Dir.mkdir("bar")
    Dir.mkdir("bar/.baz")
    FileUtils.touch("bar/.baz/qux")
    puts Dir.glob(File.join("**", "*"), File::FNM_DOTMATCH).reject{|f| File.directory?(f)}
  end
end
bug

Most helpful comment

Indeed, thanks for the report.
@bjfish Could you take a look?

All 4 comments

Indeed, thanks for the report.
@bjfish Could you take a look?

File::FNM_DOTMATCH seems to have really strange behavior, like:

% ruby -e 'p Dir.glob("**/*", File::FNM_DOTMATCH)'
[".", "bar", "bar/.", "bar/.baz", "bar/.baz/.", "bar/.baz/qux"]
% ruby -e 'p Dir.glob("**", File::FNM_DOTMATCH)' 
[".", "..", "bar"]
% ruby -e 'p Dir.glob("*", File::FNM_DOTMATCH)' 
[".", "..", "bar"]

I wonder if some of those are actually bugs in CRuby.
Matching the parent directory ("..") seems incorrect to me.

Do you know where that code is used?
Dir.glob("**/{*,.*}") or so is likely safer and more portable.

[1] pry(main)> Dir.glob("**/{*,.*}")
=> ["foo", "foo/.baz", "foo/.dir"]
[2] pry(main)> Dir.glob("**/{*,.*}", File::FNM_DOTMATCH)
=> [".", "foo", "foo/.", "foo/.baz", "foo/.dir", "foo/.dir/."]

(foo and foo/.dir are twice in the array in that case, same for bar and bar/.baz above)

I filed an issue on the CRuby tracker: https://bugs.ruby-lang.org/issues/17280

Was this page helpful?
0 / 5 - 0 ratings