[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
This commit is contained in:
parent
45177129a7
commit
6778d321a7
@ -79,10 +79,6 @@ module Bundler
|
|||||||
case @permission_type
|
case @permission_type
|
||||||
when :create
|
when :create
|
||||||
"executable permissions for all parent directories and write permissions for `#{parent_folder}`"
|
"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
|
else
|
||||||
"#{@permission_type} permissions for that path"
|
"#{@permission_type} permissions for that path"
|
||||||
end
|
end
|
||||||
@ -172,4 +168,16 @@ module Bundler
|
|||||||
|
|
||||||
status_code(32)
|
status_code(32)
|
||||||
end
|
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
|
end
|
||||||
|
@ -93,14 +93,9 @@ module Bundler
|
|||||||
private
|
private
|
||||||
|
|
||||||
def strict_rm_rf(dir)
|
def strict_rm_rf(dir)
|
||||||
# FileUtils.rm_rf should probably rise in case of permission issues like
|
Bundler.rm_rf dir
|
||||||
# `rm -rf` does. However, it fails to delete the folder silently due to
|
rescue Errno::ENOTEMPTY => e
|
||||||
# https://github.com/ruby/fileutils/issues/57. It should probably be fixed
|
raise DirectoryRemovalError.new(e.cause, "Could not delete previous installation of `#{dir}`")
|
||||||
# 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)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_bundler_checksum(checksum)
|
def validate_bundler_checksum(checksum)
|
||||||
|
@ -755,12 +755,8 @@ RSpec.describe "bundle install with gem sources" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
expect(err).not_to include("ERROR REPORT TEMPLATE")
|
expect(err).not_to include("ERROR REPORT TEMPLATE")
|
||||||
|
expect(err).to include("Could not delete previous installation of `#{foo_path}`.")
|
||||||
expect(err).to include(
|
expect(err).to include("The underlying error was Errno::EACCES")
|
||||||
"There was an error while trying to delete `#{foo_path}`. " \
|
|
||||||
"It is likely that you need to grant executable permissions for all parent directories " \
|
|
||||||
"and write permissions for `#{gems_path}`, and the same thing for all subdirectories inside #{foo_path}."
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user