Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to use --recipe-url on Windows with local file fails #7223

Merged
merged 2 commits into from May 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 11 additions & 3 deletions lib/chef/application/client.rb
Expand Up @@ -28,6 +28,7 @@
require "chef/mixin/shell_out"
require "chef-config/mixin/dot_d"
require "mixlib/archive"
require "uri"

class Chef::Application::Client < Chef::Application
include Chef::Mixin::ShellOut
Expand Down Expand Up @@ -534,10 +535,17 @@ def unrecognized_audit_mode(mode)

def fetch_recipe_tarball(url, path)
Chef::Log.trace("Download recipes tarball from #{url} to #{path}")
File.open(path, "wb") do |f|
open(url) do |r|
f.write(r.read)
if url =~ URI.regexp
File.open(path, "wb") do |f|
open(url) do |r|
f.write(r.read)
end
end
elsif File.exist?(url)
FileUtils.cp(url, path)
else
Chef::Application.fatal! "You specified --recipe-url but the value is neither a valid URL nor a path to a file that exists on disk." +
"Please confirm the location of the tarball and try again."
end
end
end
6 changes: 6 additions & 0 deletions spec/integration/client/client_spec.rb
Expand Up @@ -553,6 +553,12 @@ def match_indices(regex, str)
result = shell_out("#{chef_client} --recipe-url=http://localhost:9000/recipes.tgz", :cwd => tmp_dir)
expect(result.exitstatus).not_to eq(0)
end

it "should fail when passed --recipe-url with a file that doesn't exist" do
broken_path = File.join(CHEF_SPEC_DATA, "recipes_dont_exist.tgz")
result = shell_out("#{chef_client} --recipe-url=#{broken_path}", :cwd => tmp_dir)
expect(result.exitstatus).not_to eq(0)
end
end

when_the_repository "has a cookbook with broken metadata.rb, but has metadata.json" do
Expand Down