[macruby-changes] [5155] MacRuby/trunk/lib/rubygems/installer.rb

source_changes at macosforge.org source_changes at macosforge.org
Mon Jan 10 16:52:22 PST 2011


Revision: 5155
          http://trac.macosforge.org/projects/ruby/changeset/5155
Author:   lsansonetti at apple.com
Date:     2011-01-10 16:52:13 -0800 (Mon, 10 Jan 2011)
Log Message:
-----------
add back the fix for #766 that was forgotten during the rubygems 1.4.1 merge

Modified Paths:
--------------
    MacRuby/trunk/lib/rubygems/installer.rb

Modified: MacRuby/trunk/lib/rubygems/installer.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/installer.rb	2011-01-10 23:25:47 UTC (rev 5154)
+++ MacRuby/trunk/lib/rubygems/installer.rb	2011-01-11 00:52:13 UTC (rev 5155)
@@ -322,9 +322,41 @@
 
     # 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
+      # XXX MACRUBY do not allow executables to be overriden by a different
+      # Ruby implementation
+      #FileUtils.rm_f bin_script_path # prior install may have been --no-wrappers
 
-      File.open bin_script_path, 'w', 0755 do |file|
+      #File.open bin_script_path, 'w', 0755 do |file|
+      bin_script_exists = File.exists?(bin_script_path)
+      mode   = 'w' unless(bin_script_exists)
+      mode ||= 'r+'
+      new_shebang = shebang(filename)
+      File.open bin_script_path, mode, 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
+          begin
+            old_shebang = file.readline.chomp
+          rescue
+            old_shebang = ""
+          end
+
+          if old_shebang != 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 !@force && !ask_yes_no("Do you still wish to continue?")
+              raise Gem::InstallError, "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
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20110110/143c97e5/attachment-0001.html>


More information about the macruby-changes mailing list