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

FileUtils.chmod failes when called on symlink under linux #5547

kschoelhorn opened this issue Jan 2, 2019 · 1 comment

FileUtils.chmod failes when called on symlink under linux #5547

kschoelhorn opened this issue Jan 2, 2019 · 1 comment


Copy link

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:

@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 {
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/
   chmod at /data/software/jruby/
   chmod at /data/software/jruby/
    each at org/jruby/
   chmod at /data/software/jruby/
  <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 under RHEL 7.4.

@enebo enebo added this to the JRuby milestone Jan 9, 2019
Copy link

headius commented Apr 8, 2019

It looks like CRuby defines lchmod as an unimplemented method when it's not available; I'll modify the way we define our version to follow suit.

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