-
-
Notifications
You must be signed in to change notification settings - Fork 942
Closed
Milestone
Description
Calling FileUtils.chmod on a symlink tries to call File.lchmod if available. It checks this by calling File.lchmod with an empty file list. This succeeds, because POSIX.lchmod is not actually called in this case:
jruby/core/src/main/java/org/jruby/RubyFile.java
Lines 1010 to 1026 in d03c357
| @JRubyMethod(required = 1, rest = true, meta = true) | |
| public static IRubyObject lchmod(ThreadContext context, IRubyObject recv, IRubyObject[] args) { | |
| Ruby runtime = context.runtime; | |
| int count = 0; | |
| RubyInteger mode = args[0].convertToInteger(); | |
| for (int i = 1; i < args.length; i++) { | |
| JRubyFile file = file(args[i]); | |
| if (0 != runtime.getPosix().lchmod(file.toString(), (int) mode.getLongValue())) { | |
| throw runtime.newErrnoFromLastPOSIXErrno(); | |
| } else { | |
| count++; | |
| } | |
| } | |
| return runtime.newFixnum(count); | |
| } |
This leads to the following error, because lchmod does not exist under linux:
NotImplementedError: No message available
lchmod at org/jruby/RubyFile.java:1019
chmod at /data/software/jruby/9.2.5.0/lib/ruby/stdlib/fileutils.rb:1320
chmod at /data/software/jruby/9.2.5.0/lib/ruby/stdlib/fileutils.rb:1000
each at org/jruby/RubyArray.java:1792
chmod at /data/software/jruby/9.2.5.0/lib/ruby/stdlib/fileutils.rb:999
<main> at ./test.rb:15
This is the test program I used, which includes a workaround that makes sure File.lchmod is not considered available:
#!/usr/bin/env jruby
require 'fileutils'
# uncomment to fix NotImplementedError
# class FileUtils::Entry_
# def have_lchmod?
# false
# end
# end
FileUtils.rm_f "link"
FileUtils.ln_s "target", "link"
FileUtils.chmod 400, "link"I am using jruby 9.2.5.0 under RHEL 7.4.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels