diff options
author | Thom May <thom@may.lt> | 2018-05-04 17:57:01 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-04 17:57:01 +0100 |
commit | d0271d9f5f8918acbeb1b592c705584fe993dde1 (patch) | |
tree | 90f8c8bc7dc24a5e0902d6a33c20da46699866d5 | |
parent | 2678a7b4150a10ebb131f9443c0f9366c9ce1e47 (diff) | |
parent | 34a66ec9ab64d740c0d371f7284b8c266b147e3b (diff) | |
download | chef-d0271d9f5f8918acbeb1b592c705584fe993dde1.tar.gz |
Merge pull request #7223 from chef/windows-open-uri
Trying to use --recipe-url on Windows with local file fails
-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 28de71fa71..ffb997f187 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 @@ -534,10 +535,17 @@ class Chef::Application::Client < Chef::Application 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 diff --git a/spec/integration/client/client_spec.rb b/spec/integration/client/client_spec.rb index 201815ef01..8f2364d99a 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 |