diff options
author | David Rodriguez <deivid.rodriguez@riseup.net> | 2021-10-21 00:04:09 +0200 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2021-10-25 20:48:51 +0900 |
commit | f7f85c1febd23eec04f78bc461b21ea604a865a9 (patch) | |
tree | 752daf8cc4ee316e928fd092f063484444743b5e /lib/bundler/source | |
parent | 4fc29d17b36e12311c1fe1d2f63e463bbf8ad725 (diff) |
[rubygems/rubygems] Manage global gem cache directly
Previously, it was maintained in sync with the standard cache. That was
less efficient, and it caused some error messages to point to non
existent files.
https://github.com/rubygems/rubygems/commit/931f8cb8a9
Diffstat (limited to 'lib/bundler/source')
-rw-r--r-- | lib/bundler/source/rubygems.rb | 57 |
1 files changed, 17 insertions, 40 deletions
diff --git a/lib/bundler/source/rubygems.rb b/lib/bundler/source/rubygems.rb index a4587ac692..d0cfb07e18 100644 --- a/lib/bundler/source/rubygems.rb +++ b/lib/bundler/source/rubygems.rb @@ -357,7 +357,7 @@ module Bundler end def cached_path(spec) - possibilities = @caches.map {|p| "#{p}/#{spec.file_name}" } + possibilities = (@caches << download_cache_path(spec)).compact.map {|p| "#{p}/#{spec.file_name}" } possibilities.find {|p| File.exist?(p) } end @@ -456,9 +456,15 @@ module Bundler spec.fetch_platform - download_path = requires_sudo? ? Bundler.tmp(spec.full_name) : rubygems_dir - download_cache_path = "#{download_path}/cache" - gem_path = "#{default_cache_path}/#{spec.file_name}" + cache_path = download_cache_path(spec) || default_cache_path_for(rubygems_dir) + gem_path = "#{cache_path}/#{spec.file_name}" + + if requires_sudo? + download_path = Bundler.tmp(spec.full_name) + download_cache_path = default_cache_path_for(download_path) + else + download_cache_path = cache_path + end SharedHelpers.filesystem_access(download_cache_path) do |p| FileUtils.mkdir_p(p) @@ -466,7 +472,7 @@ module Bundler download_gem(spec, download_cache_path) if requires_sudo? - SharedHelpers.filesystem_access(default_cache_path) do |p| + SharedHelpers.filesystem_access(cache_path) do |p| Bundler.mkdir_p(p) end Bundler.sudo "mv #{download_cache_path}/#{spec.file_name} #{gem_path}" @@ -489,8 +495,8 @@ module Bundler Bundler.rubygems.gem_dir end - def default_cache_path - "#{rubygems_dir}/cache" + def default_cache_path_for(dir) + "#{dir}/cache" end def cache_path @@ -509,38 +515,9 @@ module Bundler # the local directory the .gem will end up in. # def download_gem(spec, download_cache_path) - local_path = File.join(download_cache_path, spec.file_name) - - if (cache_path = download_cache_path(spec)) && cache_path.file? - SharedHelpers.filesystem_access(local_path) do - FileUtils.cp(cache_path, local_path) - end - else - uri = spec.remote.uri - Bundler.ui.confirm("Fetching #{version_message(spec)}") - Bundler.rubygems.download_gem(spec, uri, download_cache_path) - cache_globally(spec, local_path) - end - end - - # Checks if the requested spec exists in the global cache. If it does - # not, we create the relevant global cache subdirectory if it does not - # exist and copy the spec from the local cache to the global cache. - # - # @param [Specification] spec - # the spec we want to copy to the global cache. - # - # @param [String] local_cache_path - # the local directory from which we want to copy the .gem. - # - def cache_globally(spec, local_cache_path) - return unless cache_path = download_cache_path(spec) - return if cache_path.exist? - - SharedHelpers.filesystem_access(cache_path.dirname, &:mkpath) - SharedHelpers.filesystem_access(cache_path) do - FileUtils.cp(local_cache_path, cache_path) - end + uri = spec.remote.uri + Bundler.ui.confirm("Fetching #{version_message(spec)}") + Bundler.rubygems.download_gem(spec, uri, download_cache_path) end # Returns the global cache path of the calling Rubygems::Source object. @@ -559,7 +536,7 @@ module Bundler return unless remote = spec.remote return unless cache_slug = remote.cache_slug - Bundler.user_cache.join("gems", cache_slug, spec.file_name) + Bundler.user_cache.join("gems", cache_slug) end def extension_cache_slug(spec) |