This project is archived and is in readonly mode.

#6641 new
paulbonner

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

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

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

Comments and changes to this ticket

  • paulbonner

    paulbonner March 28th, 2011 @ 10:40 PM

    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

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Tickets have moved to Github

The new ticket tracker is available at https://github.com/rails/rails/issues

Shared Ticket Bins

People watching this ticket

Pages