Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File::Stat#directory? returns false for symlink to directory with trailing slash #5539

janko opened this issue Dec 26, 2018 · 3 comments


Copy link

janko commented Dec 26, 2018


$ jruby -v
jruby (2.5.0) 2018-12-06 6d5a228 Java HotSpot(TM) 64-Bit Server VM 25.40-b25 on 1.8.0_40-b27 +jit [darwin-x86_64]
$ uname -a
Darwin Jankos-MacBook-Pro-2.local 18.2.0 Darwin Kernel Version 18.2.0: Fri Oct  5 19:41:49 PDT 2018; root:xnu-4903.221.2~2/RELEASE_X86_64 x86_64

Expected behaviour

In MRI, when a Pathname instance points to a symlink, Pathname#find will follow the symlink if you add a trailing slash. To illustrate, this script:

require "pathname"
require "tmpdir"
require "fileutils"

source_path = "#{Dir.tmpdir}/foo"
link_path   = "#{Dir.tmpdir}/foo-symlink"


FileUtils.ln_s(source_path, link_path)

Pathname(link_path).find { |path| p path }
puts "===="
Pathname("#{link_path}/").find { |path| p path }

will output the following on MRI:


Actual behaviour

JRuby won't follow the symlink on trailing slash:

Copy link

janko commented Dec 26, 2018

I managed to narrow it down to the discrepancy in File::Stat#directory? when referencing symlinks. This script:

require "tmpdir"
require "fileutils"

source_path = "#{Dir.tmpdir}/foo"
link_path   = "#{Dir.tmpdir}/foo-symlink"

FileUtils.ln_s(source_path, link_path, force: true)

puts File.lstat(link_path).directory?
puts File.lstat("#{link_path}/").directory?

outputs on MRI:


but on JRuby it outputs:


@janko janko changed the title Pathname#find with a trailing slash doesn't follow the symlink File::Stat#directory? returns false for symlink to directory with trailing slash Dec 26, 2018
Copy link

nomadium commented Jan 6, 2019

Thanks for narrowing down the issue. I could reproduce this issue in the master branch with MacOS (10.13.3) and with Linux (Debian unstable).

@enebo enebo added this to the JRuby milestone Jan 9, 2019
nomadium added a commit to nomadium/jruby that referenced this issue Jan 14, 2019
janko added a commit to shrinerb/shrine that referenced this issue Feb 4, 2019
I've reported this issue in jruby/jruby#5539,
so all we can do is wait until it's resolved.
Copy link

enebo commented Feb 15, 2019

@janko I merged @nomadium patch. Can you try jruby-head and verify this is fixed for you? I am closing as solved unless you come back and say it isn't totally fixed yet.

@enebo enebo closed this as completed Feb 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

No branches or pull requests

3 participants