Permalink
Browse files

Cache command now prunes stale .gem files from vendor/cache

If you don't want to prune, pass --no-prune to either cache or pack
  • Loading branch information...
indirect committed Apr 20, 2010
1 parent a20c08a commit 2af6b5720f9fec230d9af5f5aab5125683a13519
Showing with 75 additions and 24 deletions.
  1. +3 −0 lib/bundler/cli.rb
  2. +17 −1 lib/bundler/runtime.rb
  3. +49 −1 spec/cache/gems_spec.rb
  4. +2 −22 spec/install/gems/packed_spec.rb
  5. +4 −0 spec/support/path.rb
View
@@ -133,15 +133,18 @@ def show(gem_name = nil)
map %w(list) => "show"
desc "cache", "Cache all the gems to vendor/cache"
+ method_option "no-prune", :type => :boolean, :banner => "Don't remove stale gems from the cache."
def cache
Bundler.runtime.cache
+ Bundler.runtime.prune_cache unless options[:no_prune]
rescue GemNotFound => e
Bundler.ui.error(e.message)
Bundler.ui.warn "Run `bundle install` to install missing gems."
exit 128
end
desc "package", "Locks and then caches all of the gems into vendor/cache"
+ method_option "no-prune", :type => :boolean, :banner => "Don't remove stale gems from the cache."
def package
lock
cache
View
@@ -63,7 +63,6 @@ def dependencies_for(*groups)
alias gems specs
def cache
- cache_path = "#{root}/vendor/cache/"
FileUtils.mkdir_p(cache_path)
Bundler.ui.info "Copying .gem files into vendor/cache"
@@ -77,5 +76,22 @@ def cache
FileUtils.cp(cached_path, cache_path)
end
end
+
+ def prune_cache
+ FileUtils.mkdir_p(cache_path)
+
+ Bundler.ui.info "Removing outdated .gem files from vendor/cache"
+ cache_path.children.each do |gemfile|
+ spec = Gem::Format.from_file_by_path(gemfile).spec
+ gemfile.rmtree unless specs.include?(spec)
+ end
+ end
+
+ private
+
+ def cache_path
+ root.join("vendor/cache")
+ end
+
end
end
View
@@ -1,6 +1,7 @@
require "spec_helper"
-describe "bundle cache with gems" do
+describe "bundle cache" do
+
describe "when there are only gemsources" do
before :each do
gemfile <<-G
@@ -69,4 +70,51 @@
end
end
+ describe "when previously cached" do
+ before :each do
+ build_repo2
+ install_gemfile <<-G
+ source "file://#{gem_repo2}"
+ gem "rack"
+ gem "actionpack"
+ G
+ bundle :cache
+ cached_gem("rack-1.0.0").should exist
+ cached_gem("actionpack-2.3.2").should exist
+ cached_gem("activesupport-2.3.2").should exist
+ end
+
+ it "re-caches during install" do
+ cached_gem("rack-1.0.0").rmtree
+ bundle :install
+ out.should include("Copying .gem files into vendor/cache")
+ cached_gem("rack-1.0.0").should exist
+ end
+
+ it "adds updated gems" do
+ update_repo2
+ bundle :install
+ cached_gem("rack-1.2").should exist
+ end
+
+ it "adds new gems and dependencies" do
+ install_gemfile <<-G
+ source "file://#{gem_repo2}"
+ gem "rails"
+ G
+ cached_gem("rails-2.3.2").should exist
+ cached_gem("activerecord-2.3.2").should exist
+ end
+
+ it "removes .gems for removed gems and dependencies" do
+ install_gemfile <<-G
+ source "file://#{gem_repo2}"
+ gem "rack"
+ G
+ cached_gem("rack-1.0.0").should exist
+ cached_gem("actionpack-2.3.2").should_not exist
+ cached_gem("activesupport-2.3.2").should_not exist
+ end
+ end
+
end
@@ -32,43 +32,23 @@
err.should be_empty
should_be_installed "rack 1.0"
end
- end
- describe "when cached" do
it "ignores cached gems for the wrong platform" do
install_gemfile <<-G
Gem.platforms = [#{java}]
source "file://#{gem_repo1}"
gem "platform_specific"
G
- bundle :cache
+ bundle :pack
simulate_new_machine
- install_gemfile <<-G
+ install_gemfile <<-G, :relock => true
Gem.platforms = [#{rb}]
source "file://#{gem_repo1}"
gem "platform_specific"
G
- bundle :install
run "require 'platform_specific' ; puts PLATFORM_SPECIFIC"
out.should == "1.0.0 RUBY"
end
-
- it "updates the cache during later installs" do
- cached_gem = bundled_app("vendor/cache/rack-1.0.0.gem")
- install_gemfile <<-G
- source "file://#{gem_repo1}"
- gem "rack"
- G
-
- bundle :cache
- cached_gem.should exist
-
- FileUtils.rm_rf(cached_gem)
-
- bundle :install
- out.should include("Copying .gem files into vendor/cache")
- cached_gem.should exist
- end
end
end
View
@@ -30,6 +30,10 @@ def bundled_app2(*path)
root.join(*path)
end
+ def cached_gem(path)
+ bundled_app("vendor/cache/#{path}.gem")
+ end
+
def base_system_gems
tmp.join("gems/base")
end

0 comments on commit 2af6b57

Please sign in to comment.