Revision: 4489 http://trac.macosforge.org/projects/ruby/changeset/4489 Author: martinlagardette@apple.com Date: 2010-09-01 19:16:14 -0700 (Wed, 01 Sep 2010) Log Message: ----------- macgem asks confirmation before overriding binaries w/ different shebang - Fixes #766 Modified Paths: -------------- MacRuby/trunk/lib/rubygems/installer.rb Modified: MacRuby/trunk/lib/rubygems/installer.rb =================================================================== --- MacRuby/trunk/lib/rubygems/installer.rb 2010-09-01 23:21:37 UTC (rev 4488) +++ MacRuby/trunk/lib/rubygems/installer.rb 2010-09-02 02:16:14 UTC (rev 4489) @@ -37,6 +37,7 @@ # Raised when there is an error while building extensions. # class ExtensionBuildError < Gem::InstallError; end + class GenerateBinaryError < Gem::InstallError; end include Gem::UserInteraction @@ -321,20 +322,36 @@ # HACK some gems don't have #! in their executables, restore 2008/06 #if File.read(exec_path, 2) == '#!' then - FileUtils.rm_f bin_script_path # prior install may have been --no-wrappers + # FileUtils.rm_f bin_script_path # prior install may have been --no-wrappers - File.open bin_script_path, 'w', 0755 do |file| + bin_script_exists = File.exists?(bin_script_path) + new_shebang = shebang(filename) + File.open bin_script_path, 'r+', 0755 do |file| + if bin_script_exists + # If the first line is different than the shebang we want to insert + # we are probably overwriting a script installed by another ruby + # implementation / version + if file.readline.chomp != new_shebang + warn = <<-WARN_MESSAGE +You are installing a new version of #{bin_script_path}. +This file already exists with a different shebang, possibly from a different +ruby implementation or version. This operation may break the script. +WARN_MESSAGE + alert_warning(warn) + if not ask_yes_no("Do you still wish to continue?") + raise GenerateBinaryError, "Could not write #{bin_script_path}" + end + say "Overwrote #{bin_script_path}" if Gem.configuration.really_verbose + end + file.seek(0) + file.truncate(0) + end file.print app_script_text(filename) end say bin_script_path if Gem.configuration.really_verbose generate_windows_script bindir, filename - #else - # FileUtils.rm_f bin_script_path - # FileUtils.cp exec_path, bin_script_path, - # :verbose => Gem.configuration.really_verbose - #end end ##