aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Rodríguez <deivid.rodriguez@riseup.net>2023-10-26 18:17:22 +0200
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2023-12-05 14:28:41 +0900
commit7ab877761e0577b1cd29811173971305bfadcead (patch)
tree635e730d8adcced37a42aaa0ec52751b57c357e5
parent4a71852f757d9c18c023f3f6e993cdf55f74411d (diff)
downloadruby-7ab877761e0577b1cd29811173971305bfadcead.tar.gz
[rubygems/rubygems] Instead of checking writability, try to write
Checking writability is prone to errors. For example: $ mkdir -p foo/bar $ chmod -w foo $ touch foo/bar/baz # succeeds even if foo is not writable https://github.com/rubygems/rubygems/commit/6056138b6a
-rw-r--r--lib/rubygems/installer.rb4
-rw-r--r--test/rubygems/test_gem_commands_install_command.rb6
2 files changed, 7 insertions, 3 deletions
diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb
index 1e35e4fe83..aca42a03b0 100644
--- a/lib/rubygems/installer.rb
+++ b/lib/rubygems/installer.rb
@@ -351,6 +351,9 @@ class Gem::Installer
run_post_install_hooks
spec
+ rescue Errno::EACCES => e
+ # Permission denied - /path/to/foo
+ raise Gem::FilePermissionError, e.message.split(" - ").last
end
def run_pre_install_hooks # :nodoc:
@@ -716,7 +719,6 @@ class Gem::Installer
def verify_gem_home # :nodoc:
FileUtils.mkdir_p gem_home, :mode => options[:dir_mode] && 0o755
- raise Gem::FilePermissionError, gem_home unless File.writable?(gem_home)
end
def verify_spec
diff --git a/test/rubygems/test_gem_commands_install_command.rb b/test/rubygems/test_gem_commands_install_command.rb
index 0c4e1efc78..c38c94e5e2 100644
--- a/test/rubygems/test_gem_commands_install_command.rb
+++ b/test/rubygems/test_gem_commands_install_command.rb
@@ -193,7 +193,7 @@ ERROR: Could not find a valid gem 'bar' (= 0.5) (required by 'foo' (>= 0)) in a
pend "skipped in root privilege" if Process.uid.zero?
spec_fetcher do |fetcher|
- fetcher.gem "a", 2
+ fetcher.download "a", 2
end
@cmd.options[:user_install] = false
@@ -204,12 +204,14 @@ ERROR: Could not find a valid gem 'bar' (= 0.5) (required by 'foo' (>= 0)) in a
FileUtils.chmod 0o755, @userhome
FileUtils.chmod 0o555, @gemhome
- assert_raise Gem::FilePermissionError do
+ assert_raise Gem::MockGemUi::SystemExitException, @ui.error do
@cmd.execute
end
ensure
FileUtils.chmod 0o755, @gemhome
end
+
+ assert_equal %w[a-2], @cmd.installed_specs.map(&:full_name).sort
end
def test_execute_local_missing