1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

brace the fact that lchmod(2) can EOPNOTSUPP

Musl libc has this function as a tiny wrapper of fchmodat(3posix).  On
the other hand Linux kernel does not support changing modes of a symlink.
The operation always fails with EOPNOTSUPP.  This fchmodat behaviour is
defined in POSIX.  We have to take care of such exceptions.
This commit is contained in:
卜部昌平 2020-01-23 15:33:42 +09:00
parent 50925b6409
commit a19228f878
3 changed files with 15 additions and 9 deletions

View file

@ -1345,6 +1345,7 @@ module FileUtils
else else
File.chmod mode, path() File.chmod mode, path()
end end
rescue Errno::EOPNOTSUPP
end end
def chown(uid, gid) def chown(uid, gid)
@ -1439,7 +1440,7 @@ module FileUtils
if st.symlink? if st.symlink?
begin begin
File.lchmod mode, path File.lchmod mode, path
rescue NotImplementedError rescue NotImplementedError, Errno::EOPNOTSUPP
end end
else else
File.chmod mode, path File.chmod mode, path

View file

@ -818,7 +818,7 @@ class TestPathname < Test::Unit::TestCase
old = path.lstat.mode old = path.lstat.mode
begin begin
path.lchmod(0444) path.lchmod(0444)
rescue NotImplementedError rescue NotImplementedError, Errno::EOPNOTSUPP
next next
end end
assert_equal(0444, path.lstat.mode & 0777) assert_equal(0444, path.lstat.mode & 0777)

View file

@ -13,11 +13,11 @@ class TestNotImplement < Test::Unit::TestCase
def test_respond_to_lchmod def test_respond_to_lchmod
assert_include(File.methods, :lchmod) assert_include(File.methods, :lchmod)
if /linux/ =~ RUBY_PLATFORM case RUBY_PLATFORM
assert_equal(false, File.respond_to?(:lchmod)) when /freebsd/, /linux-musl/
end
if /freebsd/ =~ RUBY_PLATFORM
assert_equal(true, File.respond_to?(:lchmod)) assert_equal(true, File.respond_to?(:lchmod))
when /linux/
assert_equal(false, File.respond_to?(:lchmod))
end end
end end
@ -57,9 +57,14 @@ class TestNotImplement < Test::Unit::TestCase
File.open(f, "w") {} File.open(f, "w") {}
File.symlink f, g File.symlink f, g
newmode = 0444 newmode = 0444
begin
File.lchmod newmode, "#{d}/g" File.lchmod newmode, "#{d}/g"
rescue Errno::EOPNOTSUPP
skip $!
else
snew = File.lstat(g) snew = File.lstat(g)
assert_equal(newmode, snew.mode & 0777) assert_equal(newmode, snew.mode & 0777)
end
} }
end end
end end