From 6a0f7eeea9939db5188482f51cf2ee36ac4cc715 Mon Sep 17 00:00:00 2001 From: Clinton Wolfe Date: Fri, 20 Dec 2019 08:13:11 -0500 Subject: [PATCH] A terrible implementation of fetcher fallback for compliance fetcher Signed-off-by: Clinton Wolfe --- lib/inspec/dependencies/requirement.rb | 2 +- lib/inspec/dependencies/resolver.rb | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/inspec/dependencies/requirement.rb b/lib/inspec/dependencies/requirement.rb index df52cc96e..5025d2339 100644 --- a/lib/inspec/dependencies/requirement.rb +++ b/lib/inspec/dependencies/requirement.rb @@ -46,7 +46,7 @@ module Inspec req end - attr_reader :cwd, :opts, :version_constraints + attr_reader :cwd, :opts, :version_constraints, :cache def initialize(name, version_constraints, config, opts) @name = name @version_constraints = Array(version_constraints) diff --git a/lib/inspec/dependencies/resolver.rb b/lib/inspec/dependencies/resolver.rb index e722af564..b06c87de7 100644 --- a/lib/inspec/dependencies/resolver.rb +++ b/lib/inspec/dependencies/resolver.rb @@ -104,8 +104,7 @@ module Inspec # This is where any existing archives should have been inflated - # that is, this is the vendor cache. Each archive would have a lockfile. - cache_path = dep.fetcher.cache.path - fetcher = dep.fetcher.fetcher # Not the CachedFetcher, but its fetcher + cache_path = dep.cache.path worth_retrying = false Dir["#{cache_path}/*/inspec.lock"].each do |lockfile_path| @@ -114,7 +113,17 @@ module Inspec dep2 = dep_set.dep_list[dep.name] next unless dep2 - made_a_change = fetcher.update_from_opts(dep2.opts) + if dep.opts.key?(:compliance) + # This is ugly. The compliance fetcher works differently than the others, + # and fails at the resolve stage, not the fetch stage. That means we can't + # tweak the fetcher, we have to tweak the deps opts themselves. + dep.opts[:sha256] = dep2.opts[:sha256] + worth_retrying = true + else + # All other fetchers can be generalized, because they will survive their constructor. + fetcher = dep.fetcher.fetcher # Not the CachedFetcher, but its fetcher + made_a_change = fetcher.update_from_opts(dep2.opts) + end worth_retrying ||= made_a_change end worth_retrying