Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

There was a problem

You must be a member of this account.

This project is archived and is in readonly mode.

VendorGemSourceIndex::refresh! fails when vendor\gems includes CVS directory

#6641

This affects likely only us poor corporate slobs using CVS repositories. CVS creates a directory called CVS in every directory you check into its repository. This was not a problem in earlier versions of the Rails 2.x tree, but in 2.3.10 and 2.3.11, the presence of a CVS directory under vendor/gems results in an error during Rails initialization.

The source of the error appears to be a change introduced post-2.3.8 in Rails::VendorGemSourceIndex.version_for_dir.

Through 2.3.8, version_for_dir returned nil when passed a directory name like "CVS" that doesn't contain version information:

def version_for_dir(d)
  matches = /-([^-]+)$/.match(d)
  Gem::Version.new(matches[1]) if matches
end

in 2.3.10 and 2.3.11, version_for_dir returns a Gem::Version object with an empty version string given the samenon-versioned directory name:

def version_for_dir(d)
  version = d.split('-').find { |s| s.match(/^\d(\.\d|\.\w+)*$/) }
  Gem::Version.new(version)
end

As a result, the "if dir_version" check on line 70 of vendor_gem_source_index.rb fails to detect the non-versioned directory, resulting in an undefined method error on line 76:

C:/jruby-1.4.0/lib/ruby/gems/1.8/gems/rails-2.3.11/lib/rails/vendor_gem_source_index.rb:78:in `refresh!': undefined method `[]' for nil:NilClass (NoMethodError)
    from C:/jruby-1.4.0/lib/ruby/gems/1.8/gems/rails-2.3.11/lib/rails/vendor_gem_source_index.rb:45:in `each'
    from C:/jruby-1.4.0/lib/ruby/gems/1.8/gems/rails-2.3.11/lib/rails/vendor_gem_source_index.rb:45:in `refresh!'
    from C:/jruby-1.4.0/lib/ruby/gems/1.8/gems/rails-2.3.11/lib/rails/vendor_gem_source_index.rb:29:in `initialize'
    from C:/jruby-1.4.0/lib/ruby/gems/1.8/gems/rails-2.3.11/lib/rails/gem_dependency.rb:21:in `new'
    from C:/jruby-1.4.0/lib/ruby/gems/1.8/gems/rails-2.3.11/lib/rails/gem_dependency.rb:21:in `add_frozen_gem_path'
    from C:/jruby-1.4.0/lib/ruby/gems/1.8/gems/rails-2.3.11/lib/initializer.rb:298:in `add_gem_load_paths'
    from C:/jruby-1.4.0/lib/ruby/gems/1.8/gems/rails-2.3.11/lib/initializer.rb:132:in `process'
    from C:/jruby-1.4.0/lib/ruby/gems/1.8/gems/rails-2.3.11/lib/initializer.rb:113:in `run'
     ... 7 levels...
    from C:/jruby-1.4.0/lib/ruby/gems/1.8/gems/rails-2.3.11/lib/commands/server.rb:36:in `require'
    from C:/jruby-1.4.0/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
    from script\server:3

Reported by paulbonner · March 28th, 2011 @ 08:50 PM

State: new
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. paulbonner
    paulbonner

    There are two workarounds for this. The first is just to install all one's required gems and elminate the need for the vendor/gems directory. Alternately, it's possible to monkey-patch VendorGemSourceIndex in config/preinitializer.rb like this:

    require 'rubygems'
    gem 'rails'
    require 'initializer'
    
    module Rails
      class VendorGemSourceIndex
        def version_for_dir(d)
          version = d.split('-').find { |s| s.match(/^\d(\.\d|\.\w+)*$/) }
          Gem::Version.new(version) if version
        end
      end
    end@@@
    

    March 28th, 2011 @ 10:40 PM