Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

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

Closed
lighthouse-import opened this Issue May 16, 2011 · 1 comment

Comments

Projects
None yet
1 participant

Imported from Lighthouse. Original ticket at: http://rails.lighthouseapp.com/projects/8994/tickets/6641
Created by paulbonner - 2011-03-28 19:50:32 UTC

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:inrefresh!'
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:innew'
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:inadd_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:inrun'
... 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:inrequire'
from script\server:3

Imported from Lighthouse.
Comment by paulbonner - 2011-03-28 21:40:53 UTC

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment