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

JRuby raises ENOENT instead of EACCES #5617

Open
joshcooper opened this Issue Feb 14, 2019 · 1 comment

Comments

Projects
None yet
1 participant
@joshcooper
Copy link

joshcooper commented Feb 14, 2019

Environment

$ jruby -v
jruby 9.2.5.0 (2.5.0) 2018-12-06 6d5a228 Java HotSpot(TM) 64-Bit Server VM 25.162-b12 on 1.8.0_162-b12 +jit [darwin-x86_64]
$ uname -a
Darwin XXX 18.2.0 Darwin Kernel Version 18.2.0: Mon Nov 12 20:24:46 PST 2018; root:xnu-4903.231.4~2/RELEASE_X86_64 x86_64

Expected Behavior

JRuby should raise Errno::EACCES when trying to delete a file whose parent directory is unreadable by the current process, like MRI ruby does:

require 'tmpdir'
Dir.mktmpdir do |dir|
  path = File.join(dir, 'unwritable')
  begin
    File.chmod(0, dir)
    File.unlink(path)
  rescue Errno::ENOENT, Errno::EACCES => e
    puts "raised #{e.class}"
  ensure
    File.chmod(0700, dir)
  end
end
$ rbenv shell 2.5.3
$ ruby --version
ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-darwin18]
$ ruby dir.rb
raised Errno::EACCES

Actual Behavior

JRuby raises Errno::ENOENT instead, which is misleading:

$ rbenv shell jruby-9.2.5.0
$ ruby --version
jruby 9.2.5.0 (2.5.0) 2018-12-06 6d5a228 Java HotSpot(TM) 64-Bit Server VM 25.162-b12 on 1.8.0_162-b12 +jit [darwin-x86_64]
$ ruby dir.rb
raised Errno::ENOENT
@joshcooper

This comment has been minimized.

Copy link
Author

joshcooper commented Feb 14, 2019

Looks like File.stat does raise EACCES when directory permissions don't allow execute/traverse:

irb(main):005:0> File.stat('/tmp/doesnotexist')
Traceback (most recent call last):
        7: from /usr/local/opt/rbenv/versions/jruby-9.2.5.0/bin/irb:13:in `<main>'
        6: from org/jruby/RubyKernel.java:1181:in `catch'
        5: from org/jruby/RubyKernel.java:1181:in `catch'
        4: from org/jruby/RubyKernel.java:1415:in `loop'
        3: from org/jruby/RubyKernel.java:1046:in `eval'
        2: from (irb):5:in `evaluate'
        1: from org/jruby/RubyFile.java:986:in `stat'
Errno::ENOENT (No such file or directory - /tmp/doesnotexist)

joshcooper added a commit to joshcooper/puppet that referenced this issue Feb 14, 2019

(PUP-9455) Add JRuby FileSystem
When deleting a file whose parent directory is not executable, JRuby
raises ENOENT instead of EACCES[1]. To ensure consistent behavior
between MRI and JRuby, add a JRuby Puppet::FileSystem implementation and
override Posix's unlink method.

The test is skipped on Windows, because windows files can be deleted due
to processes having the "Bypass traverse checking" privilege by default.

[1] See jruby/jruby#5617
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.