Bug #16756

File.chmod does not work on links.

Added by vo.x (Vit Ondruch) 3 months ago. Updated 3 months ago.

Target version:
ruby -v:


Now I observe different error after fix of #16749:

File.lchmod changes the file mode of the link and not of the file ERROR
Errno::ENOTSUP: Operation not supported @ apply2files - /builddir/build/BUILD/ruby-2.8.0-810d66f3e7/rubyspec_temp/32136/359-file_chmod_test.lnk
/builddir/build/BUILD/ruby-2.8.0-810d66f3e7/spec/ruby/core/file/lchmod_spec.rb:21:in `lchmod'
/builddir/build/BUILD/ruby-2.8.0-810d66f3e7/spec/ruby/core/file/lchmod_spec.rb:21:in `block (3 levels) in <top (required)>'
/builddir/build/BUILD/ruby-2.8.0-810d66f3e7/spec/ruby/core/file/lchmod_spec.rb:3:in `<top (required)>'

It seems that glibc 2.31.9000 does not support lchmod above links. May be I should rather report this against glibc? Not sure ...

Updated by vo.x (Vit Ondruch) 3 months ago

I have reported this against glibc in Fedora:

Updated by fweimer (Florian Weimer) 3 months ago

This is deliberate because Linux does not support changing the mode of a symbolic link (except for file systems with bugs). The error code ENOTSUP is mandated by POSIX for this case. You can still use lchmod to avoid following symbolic links even in the presence of races, so it's still useful.

Updated by Eregon (Benoit Daloze) 3 months ago

I'm unsure how to resolve this.
This means on Linux we have File.respond_to?(:lchmod) == true but it's basically unusable for its main purpose.

I guess we'll have to do similar as, so accept both NotImplementedError and ENOTSUP and hardcode the fact Linux can't do lchmod(), because we can't detect it easily anymore.
This might break Ruby programs, notably those that would check File.respond_to?(:lchmod), and those calling lchmod but expecting only success or NotImplementedError but not ENOTSUP.

Also available in: Atom PDF