diff options
author | Tim Smith <tsmith84@gmail.com> | 2020-04-16 22:50:36 -0700 |
---|---|---|
committer | Tim Smith <tsmith84@gmail.com> | 2020-04-16 22:50:36 -0700 |
commit | 38aa51ed6d067a4be2b4abf7995f4345c43fb634 (patch) | |
tree | c81d521021b09386023feec3e1ae11de335f7720 | |
parent | 70a76bcf98e5295ff346e0a2966b1acb36073282 (diff) | |
download | chef-38aa51ed6d067a4be2b4abf7995f4345c43fb634.tar.gz |
Rework how upgrades work
See the comment for why I had to do this
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r-- | lib/chef/provider/package/homebrew.rb | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/lib/chef/provider/package/homebrew.rb b/lib/chef/provider/package/homebrew.rb index 9106725bea..4e4e9bbee3 100644 --- a/lib/chef/provider/package/homebrew.rb +++ b/lib/chef/provider/package/homebrew.rb @@ -57,14 +57,17 @@ class Chef brew_cmd_output("install", options, names.compact) end - def upgrade_package(name, version) - current_version = current_resource.version - - if current_version.nil? || current_version.empty? - install_package(name, version) - elsif current_version != version - brew_cmd_output("upgrade", options, name) - end + # upgrades are a bit harder in homebrew than other package formats. If you try to + # brew upgrade a package that isn't installed it will fail so if a user specifies + # the action of upgrade we need to figure out which packages need to be installed + # and which packages can be upgrades. We do this by checking if brew_info has an entry + # via the installed_version helper. + def upgrade_package(names, versions) + upgrade_pkgs = names.filter_map { |x| x if installed_version(x) } + install_pkgs = names.filter_map { |x| x unless installed_version(x) } + + brew_cmd_output("upgrade", options, upgrade_pkgs) unless upgrade_pkgs.empty? + brew_cmd_output("install", options, install_pkgs) unless install_pkgs.empty? end def remove_package(names, versions) |