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

Closed
janko opened this Issue Dec 26, 2018 · 3 comments

Comments

Projects
None yet
3 participants
@janko
Copy link

janko commented Dec 26, 2018

Environment

$ jruby -v
jruby 9.2.5.0 (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.rm_rf(source_path)
FileUtils.mkdir(source_path)
FileUtils.touch("#{source_path}/file")

FileUtils.rm_f(link_path)
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:

#<Pathname:/var/folders/k7/6zx6dx6x7ys3rv3srh0nyfj00000gn/T/foo-symlink>
====
#<Pathname:/var/folders/k7/6zx6dx6x7ys3rv3srh0nyfj00000gn/T/foo-symlink/>
#<Pathname:/var/folders/k7/6zx6dx6x7ys3rv3srh0nyfj00000gn/T/foo-symlink/file>

Actual behaviour

JRuby won't follow the symlink on trailing slash:

<Pathname:/var/folders/k7/6zx6dx6x7ys3rv3srh0nyfj00000gn/T/foo-symlink>
====
<Pathname:/var/folders/k7/6zx6dx6x7ys3rv3srh0nyfj00000gn/T/foo-symlink/>
@janko

This comment has been minimized.

Copy link
Author

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.mkdir_p(source_path)
FileUtils.ln_s(source_path, link_path, force: true)

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

outputs on MRI:

false
true

but on JRuby it outputs:

false
false

@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

@nomadium

This comment has been minimized.

Copy link
Contributor

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 9.2.7.0 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

Skip failing test on JRuby
I've reported this issue in jruby/jruby#5539,
so all we can do is wait until it's resolved.
@enebo

This comment has been minimized.

Copy link
Member

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 Feb 15, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.