jaruga / rpms / ruby

Forked from rpms/ruby 3 years ago
Clone
a4dab68
From 1b7c0ee13fc28a387981ae3086b40620f49831dd Mon Sep 17 00:00:00 2001
a4dab68
From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?=
a4dab68
 <shyouhei@ruby-lang.org>
a4dab68
Date: Thu, 23 Jan 2020 15:33:42 +0900
a4dab68
Subject: [PATCH 1/2] brace the fact that lchmod(2) can EOPNOTSUPP
a4dab68
a4dab68
Musl libc has this function as a tiny wrapper of fchmodat(3posix).  On
a4dab68
the other hand Linux kernel does not support changing modes of a symlink.
a4dab68
The operation always fails with EOPNOTSUPP.  This fchmodat behaviour is
a4dab68
defined in POSIX.  We have to take care of such exceptions.
a4dab68
---
a4dab68
 lib/fileutils.rb               |  3 ++-
a4dab68
 test/pathname/test_pathname.rb |  2 +-
a4dab68
 test/ruby/test_notimp.rb       | 19 ++++++++++++-------
a4dab68
 3 files changed, 15 insertions(+), 9 deletions(-)
a4dab68
a4dab68
diff --git a/lib/fileutils.rb b/lib/fileutils.rb
a4dab68
index 8981ef98e8..6332fcd6f1 100644
a4dab68
--- a/lib/fileutils.rb
a4dab68
+++ b/lib/fileutils.rb
a4dab68
@@ -1320,6 +1320,7 @@ def chmod(mode)
a4dab68
       else
a4dab68
         File.chmod mode, path()
a4dab68
       end
a4dab68
+    rescue Errno::EOPNOTSUPP
a4dab68
     end
a4dab68
 
a4dab68
     def chown(uid, gid)
a4dab68
@@ -1411,7 +1412,7 @@ def copy_metadata(path)
a4dab68
       if st.symlink?
a4dab68
         begin
a4dab68
           File.lchmod mode, path
a4dab68
-        rescue NotImplementedError
a4dab68
+        rescue NotImplementedError, Errno::EOPNOTSUPP
a4dab68
         end
a4dab68
       else
a4dab68
         File.chmod mode, path
a4dab68
diff --git a/test/pathname/test_pathname.rb b/test/pathname/test_pathname.rb
a4dab68
index f8e4937802..750fabf039 100644
a4dab68
--- a/test/pathname/test_pathname.rb
a4dab68
+++ b/test/pathname/test_pathname.rb
a4dab68
@@ -824,7 +824,7 @@ def test_lchmod
a4dab68
       old = path.lstat.mode
a4dab68
       begin
a4dab68
         path.lchmod(0444)
a4dab68
-      rescue NotImplementedError
a4dab68
+      rescue NotImplementedError, Errno::EOPNOTSUPP
a4dab68
         next
a4dab68
       end
a4dab68
       assert_equal(0444, path.lstat.mode & 0777)
a4dab68
diff --git a/test/ruby/test_notimp.rb b/test/ruby/test_notimp.rb
a4dab68
index ddebb657bf..daa5a82d7b 100644
a4dab68
--- a/test/ruby/test_notimp.rb
a4dab68
+++ b/test/ruby/test_notimp.rb
a4dab68
@@ -13,11 +13,11 @@ def test_respond_to_fork
a4dab68
 
a4dab68
   def test_respond_to_lchmod
a4dab68
     assert_include(File.methods, :lchmod)
a4dab68
-    if /linux/ =~ RUBY_PLATFORM
a4dab68
-      assert_equal(false, File.respond_to?(:lchmod))
a4dab68
-    end
a4dab68
-    if /freebsd/ =~ RUBY_PLATFORM
a4dab68
+    case RUBY_PLATFORM
a4dab68
+    when /freebsd/, /linux-musl/
a4dab68
       assert_equal(true, File.respond_to?(:lchmod))
a4dab68
+    when /linux/
a4dab68
+      assert_equal(false, File.respond_to?(:lchmod))
a4dab68
     end
a4dab68
   end
a4dab68
 
a4dab68
@@ -57,9 +57,14 @@ def test_call_lchmod
a4dab68
         File.open(f, "w") {}
a4dab68
         File.symlink f, g
a4dab68
         newmode = 0444
a4dab68
-        File.lchmod newmode, "#{d}/g"
a4dab68
-        snew = File.lstat(g)
a4dab68
-        assert_equal(newmode, snew.mode & 0777)
a4dab68
+        begin
a4dab68
+          File.lchmod newmode, "#{d}/g"
a4dab68
+        rescue Errno::EOPNOTSUPP
a4dab68
+          skip $!
a4dab68
+        else
a4dab68
+          snew = File.lstat(g)
a4dab68
+          assert_equal(newmode, snew.mode & 0777)
a4dab68
+        end
a4dab68
       }
a4dab68
     end
a4dab68
   end
a4dab68
-- 
a4dab68
2.26.2
a4dab68