summaryrefslogtreecommitdiff
path: root/lib/chef
diff options
context:
space:
mode:
authorJonathan Hartman <j@hartman.io>2018-04-09 12:42:00 -0700
committerJonathan Hartman <j@hartman.io>2018-04-09 13:17:38 -0700
commit5ba51335a24fe014b938df9c4983b1e2f3336210 (patch)
tree3f42b0bb26c98de7d6dcc418b7c2008769c87604 /lib/chef
parente7540855ccd0606b5ffc256b66d280da08555c54 (diff)
downloadchef-5ba51335a24fe014b938df9c4983b1e2f3336210.tar.gz
Fix NoMethodError when (un)locking single packages in apt and zypper
These resources don't coerce `package_name` to an array so would raise an exception when trying to call `name.all?` when `package_name`, and thus `name`, was a string. Signed-off-by: Jonathan Hartman <j@hartman.io>
Diffstat (limited to 'lib/chef')
-rw-r--r--lib/chef/provider/package/apt.rb22
-rw-r--r--lib/chef/provider/package/zypper.rb22
2 files changed, 32 insertions, 12 deletions
diff --git a/lib/chef/provider/package/apt.rb b/lib/chef/provider/package/apt.rb
index 2692ec9f15..798abf4680 100644
--- a/lib/chef/provider/package/apt.rb
+++ b/lib/chef/provider/package/apt.rb
@@ -70,12 +70,22 @@ class Chef
@candidate_version ||= get_candidate_versions
end
- def package_locked(name, version)
- locked = shell_out_compact_timeout!("apt-mark", "showhold")
- locked_packages = locked.stdout.each_line.map do |line|
- line.strip
- end
- name.all? { |n| locked_packages.include? n }
+ def packages_all_locked?(names, versions)
+ names.all? { |n| locked_packages.include? n }
+ end
+
+ def packages_all_unlocked?(names, versions)
+ names.all? { |n| !locked_packages.include? n }
+ end
+
+ def locked_packages
+ @locked_packages ||=
+ begin
+ locked = shell_out_compact_timeout!("apt-mark", "showhold")
+ locked.stdout.each_line.map do |line|
+ line.strip
+ end
+ end
end
def install_package(name, version)
diff --git a/lib/chef/provider/package/zypper.rb b/lib/chef/provider/package/zypper.rb
index 7d97bf310d..c2638fbfc1 100644
--- a/lib/chef/provider/package/zypper.rb
+++ b/lib/chef/provider/package/zypper.rb
@@ -75,12 +75,22 @@ class Chef
end
end
- def package_locked(name, version)
- locked = shell_out_compact_timeout!("zypper", "locks")
- locked_packages = locked.stdout.each_line.map do |line|
- line.split("|").shift(2).last.strip
- end
- name.all? { |n| locked_packages.include? n }
+ def packages_all_locked?(names, versions)
+ names.all? { |n| locked_packages.include? n }
+ end
+
+ def packages_all_unlocked?(names, versions)
+ names.all? { |n| !locked_packages.include? n }
+ end
+
+ def locked_packages
+ @locked_packages ||=
+ begin
+ locked = shell_out_compact_timeout!("zypper", "locks")
+ locked.stdout.each_line.map do |line|
+ line.split("|").shift(2).last.strip
+ end
+ end
end
def load_current_resource