diff options
author | Matt Wrock <matt@mattwrock.com> | 2016-01-12 09:58:40 -0800 |
---|---|---|
committer | Matt Wrock <matt@mattwrock.com> | 2016-01-12 09:58:40 -0800 |
commit | 4e2b723f880447874f1fd560fdcf69c466d3ee90 (patch) | |
tree | 3bcbe3a7b8ee5f55d4371102296e7273db7c9455 /lib/chef/provider/package | |
parent | 163dac577fd4d867696e6959cd5dc6d996fd6798 (diff) | |
parent | 7f32905c7b5600de2004f83bf4f05053db2b3b12 (diff) | |
download | chef-4e2b723f880447874f1fd560fdcf69c466d3ee90.tar.gz |
Merge pull request #4378 from chef/choco_edits
assert candidates exist for alternate sources and when pinning versions
Diffstat (limited to 'lib/chef/provider/package')
-rw-r--r-- | lib/chef/provider/package/chocolatey.rb | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/lib/chef/provider/package/chocolatey.rb b/lib/chef/provider/package/chocolatey.rb index 3f52370939..7a9173e077 100644 --- a/lib/chef/provider/package/chocolatey.rb +++ b/lib/chef/provider/package/chocolatey.rb @@ -40,6 +40,19 @@ class Chef current_resource end + def define_resource_requirements + super + + # Chocolatey source attribute points to an alternate feed + # and not a package specific alternate source like other providers + # so we want to assert candidates exist for the alternate source + requirements.assert(:upgrade, :install) do |a| + a.assertion { candidates_exist_for_all_uninstalled? } + a.failure_message(Chef::Exceptions::Package, "No candidate version available for #{packages_missing_candidates.join(", ")}") + a.whyrun("Assuming a repository that offers #{packages_missing_candidates.join(", ")} would have been configured") + end + end + # Lazy initializer for candidate_version. A nil value means that there is no candidate # version and the package is not installable (generally an error). # @@ -191,15 +204,18 @@ class Chef end # Available packages in chocolatey as a Hash of names mapped to versions + # If pinning a package to a specific version, filter out all non matching versions # (names are downcased for case-insensitive matching) # # @return [Hash] name-to-version mapping of available packages def available_packages @available_packages ||= begin - cmd = [ "list -r #{package_name_array.join ' '}" ] + cmd = [ "list -ar #{package_name_array.join ' '}" ] cmd.push( "-source #{new_resource.source}" ) if new_resource.source - parse_list_output(*cmd) + parse_list_output(*cmd).reject do |name,version| + desired_name_versions[name] && desired_name_versions[name] != version + end end end |