[rubygems/rubygems] Refactor some more duplicated logic

https://github.com/rubygems/rubygems/commit/9bd389e1b6
This commit is contained in:
David Rodríguez 2022-04-06 10:32:01 +02:00 коммит произвёл git
Родитель 95f5194b3c
Коммит 22c97ab8ae
1 изменённых файлов: 7 добавлений и 3 удалений

Просмотреть файл

@ -361,10 +361,14 @@ module Bundler
global_cache_path = download_cache_path(spec) global_cache_path = download_cache_path(spec)
@caches << global_cache_path if global_cache_path @caches << global_cache_path if global_cache_path
possibilities = @caches.map {|p| "#{p}/#{spec.file_name}" } possibilities = @caches.map {|p| package_path(p, spec) }
possibilities.find {|p| File.exist?(p) } possibilities.find {|p| File.exist?(p) }
end end
def package_path(cache_path, spec)
"#{cache_path}/#{spec.file_name}"
end
def normalize_uri(uri) def normalize_uri(uri)
uri = uri.to_s uri = uri.to_s
uri = "#{uri}/" unless uri =~ %r{/$} uri = "#{uri}/" unless uri =~ %r{/$}
@ -459,7 +463,7 @@ module Bundler
spec.fetch_platform spec.fetch_platform
cache_path = download_cache_path(spec) || default_cache_path_for(rubygems_dir) cache_path = download_cache_path(spec) || default_cache_path_for(rubygems_dir)
gem_path = "#{cache_path}/#{spec.file_name}" gem_path = package_path(cache_path, spec)
return gem_path if File.exist?(gem_path) return gem_path if File.exist?(gem_path)
if requires_sudo? if requires_sudo?
@ -478,7 +482,7 @@ module Bundler
SharedHelpers.filesystem_access(cache_path) do |p| SharedHelpers.filesystem_access(cache_path) do |p|
Bundler.mkdir_p(p) Bundler.mkdir_p(p)
end end
Bundler.sudo "mv #{download_cache_path}/#{spec.file_name} #{gem_path}" Bundler.sudo "mv #{package_path(download_cache_path, spec)} #{gem_path}"
end end
gem_path gem_path