diff options
author | Josh Barker <josh.barker.developer@gmail.com> | 2018-05-26 15:56:12 +1000 |
---|---|---|
committer | Josh Barker <josh.barker@au1.ibm.com> | 2018-06-07 09:32:35 +1000 |
commit | a8fd0ad3001483146fb49000b4d73ba77d3bd94a (patch) | |
tree | 8040fdb9b9a5299ce1c0066a77e30ba2112adf19 | |
parent | cf0f38ca3a4ed2de5b8c9b540014c0a2ae3881b5 (diff) | |
download | chef-a8fd0ad3001483146fb49000b4d73ba77d3bd94a.tar.gz |
Check local file exists before installing a windows package
Signed-off-by: Josh Barker <josh.barker.developer@gmail.com>
(cherry picked from commit da8dcb98cf650708b6a9d44fa6ef2339e0b0f64c)
-rw-r--r-- | lib/chef/provider/package/windows.rb | 7 | ||||
-rw-r--r-- | spec/unit/provider/package/windows_spec.rb | 12 |
2 files changed, 19 insertions, 0 deletions
diff --git a/lib/chef/provider/package/windows.rb b/lib/chef/provider/package/windows.rb index bade7f27a3..9df9954b01 100644 --- a/lib/chef/provider/package/windows.rb +++ b/lib/chef/provider/package/windows.rb @@ -39,6 +39,13 @@ class Chef a.assertion { new_resource.source || msi? } a.failure_message Chef::Exceptions::NoWindowsPackageSource, "Source for package #{new_resource.name} must be specified in the resource's source property for package to be installed because the package_name property is used to test for the package installation state for this package type." end + + unless uri_scheme?(new_resource.source) + requirements.assert(:install) do |a| + a.assertion { ::File.exist?(new_resource.source) } + a.failure_message Chef::Exceptions::Package, "Source for package #{new_resource.name} does not exist" + end + end end # load_current_resource is run in Chef::Provider#run_action when not in whyrun_mode? diff --git a/spec/unit/provider/package/windows_spec.rb b/spec/unit/provider/package/windows_spec.rb index d07e68cb5b..0f4fd465c8 100644 --- a/spec/unit/provider/package/windows_spec.rb +++ b/spec/unit/provider/package/windows_spec.rb @@ -394,6 +394,18 @@ describe Chef::Provider::Package::Windows, :windows_only do end end end + + context "a missing local file is given" do + let(:resource_source) { "C:/a_missing_file.exe" } + let(:installer_type) { nil } + + it "raises a Package error" do + allow(::File).to receive(:exist?).with(provider.new_resource.source).and_return(false) + + provider.load_current_resource + expect { provider.run_action(:install) }.to raise_error(Chef::Exceptions::Package) + end + end end shared_context "valid checksum" do |