Skip to content

Commit

Permalink
Don't consider local files in remote only mode. RG #26109
Browse files Browse the repository at this point in the history
  • Loading branch information
evanphx committed Jun 1, 2011
1 parent 7e6f8e5 commit fe493ea
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 15 deletions.
33 changes: 18 additions & 15 deletions lib/rubygems/dependency_installer.rb
Expand Up @@ -202,23 +202,26 @@ def add_found_dependencies to_do, dependency_list
def find_spec_by_name_and_version(gem_name,
version = Gem::Requirement.default,
prerelease = false)
spec_and_source = nil

glob = if File::ALT_SEPARATOR then
gem_name.gsub File::ALT_SEPARATOR, File::SEPARATOR
else
gem_name
end

local_gems = Dir["#{glob}*"].sort.reverse
spec_and_source = nil

local_gems.each do |gem_file|
next unless gem_file =~ /gem$/
begin
spec = Gem::Format.from_file_by_path(gem_file).spec
spec_and_source = [spec, gem_file]
break
rescue SystemCallError, Gem::Package::FormatError
if @domain != :remote
glob = if File::ALT_SEPARATOR then
gem_name.gsub File::ALT_SEPARATOR, File::SEPARATOR
else
gem_name
end

local_gems = Dir["#{glob}*"].sort.reverse

local_gems.each do |gem_file|
next unless gem_file =~ /gem$/
begin
spec = Gem::Format.from_file_by_path(gem_file).spec
spec_and_source = [spec, gem_file]
break
rescue SystemCallError, Gem::Package::FormatError
end
end
end

Expand Down
42 changes: 42 additions & 0 deletions test/rubygems/test_gem_commands_install_command.rb
Expand Up @@ -256,6 +256,48 @@ def test_execute_remote
assert out.empty?, out.inspect
end

def test_execute_remote_ignores_files
util_setup_fake_fetcher
util_setup_spec_fetcher

@cmd.options[:domain] = :remote

FileUtils.mv @a2.cache_file, @tempdir

@fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] =
read_binary(@a1.cache_file)

@cmd.options[:args] = [@a2.name]

gemdir = File.join @gemhome, 'specifications'

a2_gemspec = File.join(gemdir, "a-2.gemspec")
a1_gemspec = File.join(gemdir, "a-1.gemspec")

FileUtils.rm_rf a1_gemspec
FileUtils.rm_rf a2_gemspec

start = Dir["#{gemdir}/*"]

use_ui @ui do
Dir.chdir @tempdir do
e = assert_raises Gem::SystemExitException do
@cmd.execute
end
assert_equal 0, e.exit_code
end
end

out = @ui.output.split "\n"
assert_equal "Successfully installed #{@a1.full_name}", out.shift
assert_equal "1 gem installed", out.shift
assert out.empty?, out.inspect

fin = Dir["#{gemdir}/*"]

assert_equal [a1_gemspec], fin - start
end

def test_execute_two
util_setup_fake_fetcher
@cmd.options[:domain] = :local
Expand Down

0 comments on commit fe493ea

Please sign in to comment.