Rename some vars, eliminate @profile_directory

Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
This commit is contained in:
Clinton Wolfe 2019-06-19 23:44:13 -04:00
parent 4f6d296a22
commit 1a47026419

View file

@ -41,7 +41,6 @@ module Fetchers
@ref = opts[:ref] @ref = opts[:ref]
@remote_url = expand_local_path(remote_url) @remote_url = expand_local_path(remote_url)
@repo_directory = nil @repo_directory = nil
@profile_directory = nil # TODO remove this if possible, distinction without a difference
@relative_path = opts[:relative_path] @relative_path = opts[:relative_path]
end end
@ -59,33 +58,30 @@ module Fetchers
File.expand_path(url_or_file_path) File.expand_path(url_or_file_path)
end end
def fetch(dir) def fetch(destination_path)
@repo_directory = dir @repo_directory = destination_path
FileUtils.mkdir_p(dir) unless Dir.exist?(dir) FileUtils.mkdir_p(destination_path) unless Dir.exist?(destination_path)
if cloned? if cloned?
checkout checkout
else else
Dir.mktmpdir do |tmpdir| Dir.mktmpdir do |working_dir|
checkout(tmpdir) checkout(working_dir)
if @relative_path if @relative_path
@profile_directory = dir
Inspec::Log.debug("Checkout of #{resolved_ref} successful. " \ Inspec::Log.debug("Checkout of #{resolved_ref} successful. " \
"Moving #{@relative_path} to #{dir}") "Moving #{@relative_path} to #{destination_path}")
unless File.exist?("#{tmpdir}/#{@relative_path}") unless File.exist?("#{working_dir}/#{@relative_path}")
raise ArgumentError.new("Cannot find relative path '#{@relative_path}' within profile in git repo specified by '#{@remote_url}'") raise ArgumentError.new("Cannot find relative path '#{@relative_path}' within profile in git repo specified by '#{@remote_url}'")
end end
target_profile = File.join(tmpdir, @relative_path) FileUtils.cp_r("#{working_dir}/#{@relative_path}", destination_path)
FileUtils.cp_r(target_profile, dir)
else else
Inspec::Log.debug("Checkout of #{resolved_ref} successful. " \ Inspec::Log.debug("Checkout of #{resolved_ref} successful. " \
"Moving checkout to #{dir}") "Moving checkout to #{destination_path}")
FileUtils.cp_r(tmpdir + "/.", dir) FileUtils.cp_r(working_dir + "/.", destination_path)
end end
end end
end end
@profile_directory || @repo_directory @repo_directory
end end
def cache_key def cache_key
@ -94,7 +90,7 @@ module Fetchers
end end
def archive_path def archive_path
@profile_directory || @repo_directory @repo_directory
end end
def resolved_source def resolved_source