Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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...
commit 1d5b0696cf0f0b2d53e96143ff6d2e8c1a128313 1 parent 20d36fd
@indirect indirect authored
View
3  lib/bundler/cli.rb
@@ -143,8 +143,10 @@ 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."
@@ -152,6 +154,7 @@ def cache
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
15 lib/bundler/runtime.rb
@@ -79,7 +79,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"
@@ -94,12 +93,26 @@ def cache
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 load_paths
specs.map { |s| s.load_paths }.flatten
end
+ def cache_path
+ root.join("vendor/cache")
+ end
+
def write_yml_lock
yml = details.to_yaml
File.open("#{root}/Gemfile.lock", 'w') do |f|
View
50 spec/cache/gems_spec.rb
@@ -1,6 +1,7 @@
require File.expand_path('../../spec_helper', __FILE__)
-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
View
24 spec/install/gems/packed_spec.rb
@@ -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
4 spec/support/path.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.