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
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
This is now fixed at: https://github.com/oracle/truffleruby/commit/72d1f415e0472bc86a85b662d5539f96c8c92153
Most helpful comment
Indeed, thanks for the report.
@bjfish Could you take a look?