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

Closed
kschoelhorn opened this issue Jan 2, 2019 · 1 comment
Closed

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

kschoelhorn opened this issue Jan 2, 2019 · 1 comment
Milestone

Comments

@kschoelhorn
Copy link
Contributor

@kschoelhorn kschoelhorn commented Jan 2, 2019

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 {
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.

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

@headius 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.

@headius headius closed this in e36a5e9 Apr 8, 2019
headius added a commit that referenced this issue Apr 9, 2019
See #5547
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants