From bf367148a45bfc56142db4d4fc32f137e1056f60 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Thu, 15 Jul 2010 10:28:56 -0700 Subject: Don't claim to be deleting gems from vendor/cache when nothing actually happens --- lib/bundler/runtime.rb | 21 +++++++++++++++------ spec/cache/gems_spec.rb | 12 +++++++++++- spec/cache/path_spec.rb | 4 ++-- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb index efcee1c5b6..a3cbac1cf6 100644 --- a/lib/bundler/runtime.rb +++ b/lib/bundler/runtime.rb @@ -86,13 +86,22 @@ module Bundler FileUtils.mkdir_p(cache_path) resolve = @definition.resolve + cached = Dir["#{cache_path}/*.gem"] - Bundler.ui.info "Removing outdated .gem files from vendor/cache" - Pathname.glob(cache_path.join("*.gem").to_s).each do |gem_path| - cached = Gem::Format.from_file_by_path(gem_path).spec - unless resolve.any?{|s| s.name == cached.name && s.version == cached.version } - Bundler.ui.info " * #{File.basename(gem_path)}" - gem_path.rmtree + cached = cached.delete_if do |path| + spec = Gem::Format.from_file_by_path(path).spec + + resolve.any? do |s| + s.name == spec.name && s.version == spec.version + end + end + + if cached.any? + Bundler.ui.info "Removing outdated .gem files from vendor/cache" + + cached.each do |path| + Bundler.ui.info " * #{File.basename(path)}" + File.delete(path) end end end diff --git a/spec/cache/gems_spec.rb b/spec/cache/gems_spec.rb index 8f80b6e5cc..088a34709d 100644 --- a/spec/cache/gems_spec.rb +++ b/spec/cache/gems_spec.rb @@ -157,6 +157,16 @@ describe "bundle cache" do File.open(bundled_app("vendor/cache/bar"), 'w'){|f| f.write("not a gem") } bundle :cache end + + it "does not say that it is removing gems when it isn't actually doing so" do + install_gemfile <<-G + source "file://#{gem_repo1}" + gem "rack" + G + bundle "cache" + bundle "install" + out.should_not =~ /removing/i + end end -end \ No newline at end of file +end diff --git a/spec/cache/path_spec.rb b/spec/cache/path_spec.rb index 10c1e77716..6a78ac3b5e 100644 --- a/spec/cache/path_spec.rb +++ b/spec/cache/path_spec.rb @@ -10,7 +10,7 @@ describe "bundle cache" do G bundle "cache" - out.should == "Updating .gem files in vendor/cache\nRemoving outdated .gem files from vendor/cache" + out.should == "Updating .gem files in vendor/cache" end it "warns when the path is outside of the bundle" do @@ -24,4 +24,4 @@ describe "bundle cache" do out.should include("foo at `#{lib_path("foo-1.0")}` will not be cached") end end -end \ No newline at end of file +end -- cgit v1.2.1