diff options
author | David RodrÃguez <deivid.rodriguez@riseup.net> | 2022-05-25 11:03:33 +0200 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2022-05-27 17:26:22 +0900 |
commit | 6778d321a7fa0ec56e3e02b6f3739a035c7ef41a (patch) | |
tree | 278712da8c20b1ba77762570756ff85a1856e74f /lib/bundler | |
parent | 45177129a75c5bfd03933b82076e8dc49acc500f (diff) |
[rubygems/rubygems] Show better error when previous installation fails to be removed
Instead of guessing on the culprit.
We actually have a helper, `Bundler.rm_rf`, with exactly the behavior
that we want:
* Allow the passed folder to not exist.
* No exception swallowing other than that.
https://github.com/rubygems/rubygems/commit/5fa3e6f04a
Diffstat (limited to 'lib/bundler')
-rw-r--r-- | lib/bundler/errors.rb | 16 | ||||
-rw-r--r-- | lib/bundler/rubygems_gem_installer.rb | 11 |
2 files changed, 15 insertions, 12 deletions
diff --git a/lib/bundler/errors.rb b/lib/bundler/errors.rb index 9ad7460e58..0bc1a860df 100644 --- a/lib/bundler/errors.rb +++ b/lib/bundler/errors.rb @@ -79,10 +79,6 @@ module Bundler case @permission_type when :create "executable permissions for all parent directories and write permissions for `#{parent_folder}`" - when :delete - permissions = "executable permissions for all parent directories and write permissions for `#{parent_folder}`" - permissions += ", and the same thing for all subdirectories inside #{@path}" if File.directory?(@path) - permissions else "#{@permission_type} permissions for that path" end @@ -172,4 +168,16 @@ module Bundler status_code(32) end + + class DirectoryRemovalError < BundlerError + def initialize(orig_exception, msg) + full_message = "#{msg}.\n" \ + "The underlying error was #{orig_exception.class}: #{orig_exception.message}, with backtrace:\n" \ + " #{orig_exception.backtrace.join("\n ")}\n\n" \ + "Bundler Error Backtrace:" + super(full_message) + end + + status_code(36) + end end diff --git a/lib/bundler/rubygems_gem_installer.rb b/lib/bundler/rubygems_gem_installer.rb index 452583617b..87b9772c27 100644 --- a/lib/bundler/rubygems_gem_installer.rb +++ b/lib/bundler/rubygems_gem_installer.rb @@ -93,14 +93,9 @@ module Bundler private def strict_rm_rf(dir) - # FileUtils.rm_rf should probably rise in case of permission issues like - # `rm -rf` does. However, it fails to delete the folder silently due to - # https://github.com/ruby/fileutils/issues/57. It should probably be fixed - # inside `fileutils` but for now I`m checking whether the folder was - # removed after it completes, and raising otherwise. - FileUtils.rm_rf dir - - raise PermissionError.new(dir, :delete) if File.directory?(dir) + Bundler.rm_rf dir + rescue Errno::ENOTEMPTY => e + raise DirectoryRemovalError.new(e.cause, "Could not delete previous installation of `#{dir}`") end def validate_bundler_checksum(checksum) |