[MacRuby] #905: Can't install the rubygems that create a file in "/usr/bin/".

MacRuby ruby-noreply at macosforge.org
Fri Sep 17 00:51:58 PDT 2010


#905: Can't install the rubygems that create a file in "/usr/bin/".
----------------------------------+-----------------------------------------
 Reporter:  watson1978@…          |       Owner:  lsansonetti@…        
     Type:  defect                |      Status:  new                  
 Priority:  blocker               |   Milestone:                       
Component:  MacRuby               |    Keywords:  0.7-blocker          
----------------------------------+-----------------------------------------

Comment(by watson1978@…):

 I atach a pach.
 {{{
 #!diff
 diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb
 index 999a1be..7c1b28e 100644
 --- a/lib/rubygems/installer.rb
 +++ b/lib/rubygems/installer.rb
 @@ -325,13 +325,21 @@ class Gem::Installer
        # FileUtils.rm_f bin_script_path # prior install may have been
 --no-wrappers

        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, 'r+', 0755 do |file|
 +      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
 -          if file.readline.chomp != new_shebang
 +          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
 }}}

 Result:
 {{{
 $ sudo rm /usr/bin/hotcocoa
 $ sudo macgem install hotcocoaSuccessfully installed hotcocoa-0.5.1
 1 gem installed

 $ sudo rm /usr/bin/hotcocoa
 $ sudo touch /usr/bin/hotcocoa
 $ sudo macgem install hotcocoa
 WARNING:  You are installing a new version of /usr/bin/hotcocoa.
 This file already exists with a different shebang, possibly from a
 different
 ruby implementation or version. This operation may break the script.
 Do you still wish to continue? [yn]  y
 Successfully installed hotcocoa-0.5.1
 1 gem installed

 $ sudo rm /usr/bin/hotcocoa
 $ echo '#!ruby' | sudo tee -i /usr/bin/hotcocoa#!ruby
 $ sudo macgem install hotcocoa
 WARNING:  You are installing a new version of /usr/bin/hotcocoa.
 This file already exists with a different shebang, possibly from a
 different
 ruby implementation or version. This operation may break the script.
 Do you still wish to continue? [yn]  y
 Successfully installed hotcocoa-0.5.1
 1 gem installed
 }}}

-- 
Ticket URL: <http://www.macruby.org/trac/ticket/905#comment:5>
MacRuby <http://macruby.org/>



More information about the macruby-tickets mailing list