diff options
author | tyler-ball <tyleraball@gmail.com> | 2018-05-03 17:31:55 -0600 |
---|---|---|
committer | tyler-ball <tball@chef.io> | 2018-07-05 16:45:39 -0600 |
commit | d4a06c375a151e033e5e9a8718e4a25264c6d3d3 (patch) | |
tree | 519a6a0e4453e6a19bbc7e93a2857eda8a6cf1b7 | |
parent | 8419e14631575ba22380893648bf16bdc684bef3 (diff) | |
download | chef-d4a06c375a151e033e5e9a8718e4a25264c6d3d3.tar.gz |
Trying to use --recipe-url on Windows with local file fails
Backporting https://github.com/chef/chef/pull/7223 to Chef 13
Signed-off-by: tyler-ball <tball@chef.io>
-rw-r--r-- | lib/chef/application/client.rb | 14 | ||||
-rw-r--r-- | spec/integration/client/client_spec.rb | 6 |
2 files changed, 17 insertions, 3 deletions
diff --git a/lib/chef/application/client.rb b/lib/chef/application/client.rb index 32530925d5..7713350352 100644 --- a/lib/chef/application/client.rb +++ b/lib/chef/application/client.rb @@ -28,6 +28,7 @@ require "chef/workstation_config_loader" 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 @@ -528,10 +529,17 @@ class Chef::Application::Client < Chef::Application def fetch_recipe_tarball(url, path) Chef::Log.debug("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 diff --git a/spec/integration/client/client_spec.rb b/spec/integration/client/client_spec.rb index de12b8ba8e..b7eb3b1d07 100644 --- a/spec/integration/client/client_spec.rb +++ b/spec/integration/client/client_spec.rb @@ -553,6 +553,12 @@ EOM 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 |