diff options
author | Samuel Giddins <segiddins@segiddins.me> | 2016-08-02 14:44:15 -0500 |
---|---|---|
committer | Samuel Giddins <segiddins@segiddins.me> | 2016-08-05 18:32:24 -0500 |
commit | abeae826c9ec277a22c7cde6713b5a3654a54d42 (patch) | |
tree | ac3aabda7bb669bf6004bbe888db4d32d137f29d | |
parent | 6abce36b12e47e48e89ac6e85b1a9eafed4ffcd8 (diff) | |
download | bundler-abeae826c9ec277a22c7cde6713b5a3654a54d42.tar.gz |
Allow installing / updating when everything necessary is available locally
-rw-r--r-- | lib/bundler/fetcher/compact_index.rb | 19 | ||||
-rw-r--r-- | lib/bundler/settings.rb | 1 | ||||
-rw-r--r-- | lib/bundler/source/git.rb | 9 |
3 files changed, 22 insertions, 7 deletions
diff --git a/lib/bundler/fetcher/compact_index.rb b/lib/bundler/fetcher/compact_index.rb index b51ba150a9..fb77451822 100644 --- a/lib/bundler/fetcher/compact_index.rb +++ b/lib/bundler/fetcher/compact_index.rb @@ -78,11 +78,7 @@ module Bundler private def compact_index_client - @compact_index_client ||= begin - compact_fetcher = lambda do |path, headers| - downloader.fetch(fetch_uri + path, headers) - end - + @compact_index_client ||= SharedHelpers.filesystem_access(cache_path) do CompactIndexClient.new(cache_path, compact_fetcher) end.tap do |client| @@ -93,7 +89,6 @@ module Bundler inputs.map { worker.deq } end end - end end def bundle_worker(func = nil) @@ -109,6 +104,18 @@ module Bundler def cache_path Bundler.user_cache.join("compact_index", remote.cache_slug) end + + def compact_fetcher + lambda do |path, headers| + begin + downloader.fetch(fetch_uri + path, headers) + rescue NetworkDownError => e + raise unless Bundler.settings[:allow_offline_install] && headers["If-None-Match"] + Bundler.ui.warn "Using the cached data for the new index because of a network error: #{e}" + Net::HTTPNotModified.new(nil, nil, nil) + end + end + end end end end diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb index 0c846d195c..e5c2581067 100644 --- a/lib/bundler/settings.rb +++ b/lib/bundler/settings.rb @@ -4,6 +4,7 @@ require "uri" module Bundler class Settings BOOL_KEYS = %w( + allow_offline_install cache_all disable_local_branch_check disable_shared_gems diff --git a/lib/bundler/source/git.rb b/lib/bundler/source/git.rb index 5344ab694f..60fb555f0a 100644 --- a/lib/bundler/source/git.rb +++ b/lib/bundler/source/git.rb @@ -152,7 +152,7 @@ module Bundler set_local!(app_cache_path) if has_app_cache? && !local? if requires_checkout? && !@copied - git_proxy.checkout + fetch git_proxy.copy_to(install_path, submodules) serialize_gemspecs_in(install_path) @copied = true @@ -288,6 +288,13 @@ module Bundler def git_proxy @git_proxy ||= GitProxy.new(cache_path, uri, ref, cached_revision, self) end + + def fetch + git_proxy.checkout + rescue GitError + raise unless Bundler.settings[:allow_offline_install] + Bundler.ui.warn "Using cached git data because of network errors" + end end end end |