diff options
author | José Valim <jose.valim@plataformatec.com.br> | 2012-07-17 10:22:12 +0200 |
---|---|---|
committer | José Valim <jose.valim@plataformatec.com.br> | 2012-07-17 10:22:12 +0200 |
commit | 1bd97f3c13c6a7d92d6b8eb62d8644400a06d21a (patch) | |
tree | 64858cf4540d99e38dbc00816d4354ff96b84723 | |
parent | 51aaf18a0e2d8a76a44f789d0e31b4d2ce123024 (diff) | |
download | bundler-1bd97f3c13c6a7d92d6b8eb62d8644400a06d21a.tar.gz |
Prune git and path directories inside vendor/cache, closes #1988
From this commit on, we add a .bundlecache file inside
each git/path directory in vendor/cache so we know it
came from bundler. This allow us to delete those specific
directories without messing with user's specific ones.
-rw-r--r-- | lib/bundler/runtime.rb | 65 | ||||
-rw-r--r-- | lib/bundler/source.rb | 16 | ||||
-rw-r--r-- | spec/cache/git_spec.rb | 2 | ||||
-rw-r--r-- | spec/cache/path_spec.rb | 18 |
4 files changed, 77 insertions, 24 deletions
diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb index 52e3dc6e51..7a759a534e 100644 --- a/lib/bundler/runtime.rb +++ b/lib/bundler/runtime.rb @@ -107,26 +107,9 @@ module Bundler def prune_cache FileUtils.mkdir_p(cache_path) unless File.exists?(cache_path) - resolve = @definition.resolve - cached = Dir["#{cache_path}/*.gem"] - - cached = cached.delete_if do |path| - spec = Bundler.rubygems.spec_from_gem path - - resolve.any? do |s| - s.name == spec.name && s.version == spec.version && !s.source.is_a?(Bundler::Source::Git) - 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 + prune_gem_cache(resolve) + prune_git_and_path_cache(resolve) end def clean @@ -226,6 +209,50 @@ module Bundler private + def prune_gem_cache(resolve) + cached = Dir["#{cache_path}/*.gem"] + + cached = cached.delete_if do |path| + spec = Bundler.rubygems.spec_from_gem path + + resolve.any? do |s| + s.name == spec.name && s.version == spec.version && !s.source.is_a?(Bundler::Source::Git) + 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 + + def prune_git_and_path_cache(resolve) + cached = Dir["#{cache_path}/*/.bundlecache"] + + cached = cached.delete_if do |path| + name = File.basename(File.dirname(path)) + + resolve.any? do |s| + source = s.source + source.respond_to?(:app_cache_dirname) && source.app_cache_dirname == name + end + end + + if cached.any? + Bundler.ui.info "Removing outdated .git/path repos from vendor/cache" + + cached.each do |path| + path = File.dirname(path) + Bundler.ui.info " * #{File.basename(path)}" + FileUtils.rm_rf(path) + end + end + end + def cache_path root.join("vendor/cache") end diff --git a/lib/bundler/source.rb b/lib/bundler/source.rb index e4117dd18f..4f2ce4e7b1 100644 --- a/lib/bundler/source.rb +++ b/lib/bundler/source.rb @@ -374,6 +374,7 @@ module Bundler return if @original_path.expand_path(Bundler.root).to_s.index(Bundler.root.to_s) == 0 FileUtils.rm_rf(app_cache_path) FileUtils.cp_r("#{@original_path}/.", app_cache_path) + FileUtils.touch(app_cache_path.join(".bundlecache")) end def local_specs(*) @@ -387,10 +388,14 @@ module Bundler local_specs end + def app_cache_dirname + name + end + private def app_cache_path - @app_cache_path ||= Bundler.app_cache.join(name) + @app_cache_path ||= Bundler.app_cache.join(app_cache_dirname) end def has_app_cache? @@ -787,6 +792,7 @@ module Bundler git_proxy.checkout if requires_checkout? git_proxy.copy_to(app_cache_path, @submodules) FileUtils.rm_rf(app_cache_path.join(".git")) + FileUtils.touch(app_cache_path.join(".bundlecache")) end def load_spec_files @@ -811,6 +817,10 @@ module Bundler end end + def app_cache_dirname + "#{base_name}-#{shortref_for_path(cached_revision || revision)}" + end + private def set_local!(path) @@ -823,10 +833,6 @@ module Bundler cached_revision && super end - def app_cache_path - @app_cache_path ||= Bundler.app_cache.join("#{base_name}-#{shortref_for_path(cached_revision || revision)}") - end - def local? @local end diff --git a/spec/cache/git_spec.rb b/spec/cache/git_spec.rb index 219d191387..6958bc3893 100644 --- a/spec/cache/git_spec.rb +++ b/spec/cache/git_spec.rb @@ -25,6 +25,7 @@ end bundle "#{cmd} --all" bundled_app("vendor/cache/foo-1.0-#{ref}").should exist bundled_app("vendor/cache/foo-1.0-#{ref}/.git").should_not exist + bundled_app("vendor/cache/foo-1.0-#{ref}/.bundlecache").should be_file FileUtils.rm_rf lib_path("foo-1.0") should_be_installed "foo 1.0" @@ -84,6 +85,7 @@ end bundle "#{cmd} --all" bundled_app("vendor/cache/foo-1.0-#{ref}").should exist + bundled_app("vendor/cache/foo-1.0-#{old_ref}").should_not exist FileUtils.rm_rf lib_path("foo-1.0") run "require 'foo'" diff --git a/spec/cache/path_spec.rb b/spec/cache/path_spec.rb index a50e5d9331..94c451819a 100644 --- a/spec/cache/path_spec.rb +++ b/spec/cache/path_spec.rb @@ -23,6 +23,7 @@ require "spec_helper" bundle "#{cmd} --all" bundled_app("vendor/cache/foo-1.0").should exist + bundled_app("vendor/cache/foo-1.0/.bundlecache").should be_file FileUtils.rm_rf lib_path("foo-1.0") should_be_installed "foo 1.0" @@ -50,6 +51,23 @@ require "spec_helper" out.should == "CACHE" end + it "removes stale entries cache" do + build_lib "foo" + + install_gemfile <<-G + gem "foo", :path => '#{lib_path("foo-1.0")}' + G + + bundle "#{cmd} --all" + + install_gemfile <<-G + gem "bar", :path => '#{lib_path("bar-1.0")}' + G + + bundle "#{cmd} --all" + bundled_app("vendor/cache/bar-1.0").should_not exist + end + it "raises a warning without --all" do build_lib "foo" |