Kurt Stephens

Nerd Up!

Recent comments

Random image

Latest image

Syndicate

Syndicate content

Browse archives

« November 2008  
Mo Tu We Th Fr Sa Su
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15
17 18 19 20 21 22
24 25 26 27 28 29 30
Kurt on Wed, 2007-10-17 14:37.

Gem::SourceIndex does not honor GEM_PATH ordering.

See: http://rubyforge.org/tracker/index.php?func=detail&aid=14816&group_id=12...

Gem::SourceIndex#load_gems_in calls #add_spec for all gems found in #spec_dirs, in the order of Gem.path, however #add_spec
overwrites previous gem_specs in the @gems Hash:


    # Add a gem specification to the source index.
    def add_spec(gem_spec)
      @gems[gem_spec.full_name] = gem_spec
    end

Thus: if a gem xyz-1.2.3 exists in multiple gems install directories along Gem.path, the last one found in the Gem.path
is saved, not the first one found; very unexpected.

I think this would fix it:


    # Add a gem specification to the source index.
    def add_spec(gem_spec, overwrite = false)
      @gems[gem_spec.full_name] = nil if overwrite
      @gems[gem_spec.full_name] ||= gem_spec
    end

If other callers to #add_spec need to overwrite, they could call #add_spec(gem_spec, true) or some variant.

This was causing problems with gems that were corrupted further in the Gem.path (e.g.: /usr/lib/ruby by an errant superuser),
but were correctly installed earlier in Gem.path (e.g.: correct installation in $HOME/gems).

links: read more | Kurt's blog | add new comment | 605 reads

Reply

The content of this field is kept private and will not be shown publicly.
Captcha Image: you will need to recognize the text in it.
Please type in the letters/numbers that are shown in the image above.