summaryrefslogtreecommitdiff
path: root/lib/chef/provider/package
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chef/provider/package')
-rw-r--r--lib/chef/provider/package/apt.rb3
-rw-r--r--lib/chef/provider/package/bff.rb1
-rw-r--r--lib/chef/provider/package/cab.rb2
-rw-r--r--lib/chef/provider/package/chocolatey.rb3
-rw-r--r--lib/chef/provider/package/dnf/python_helper.rb1
-rw-r--r--lib/chef/provider/package/freebsd/base.rb1
-rw-r--r--lib/chef/provider/package/macports.rb1
-rw-r--r--lib/chef/provider/package/msu.rb2
-rw-r--r--lib/chef/provider/package/paludis.rb1
-rw-r--r--lib/chef/provider/package/powershell.rb1
-rw-r--r--lib/chef/provider/package/rpm.rb1
-rw-r--r--lib/chef/provider/package/rubygems.rb2
-rw-r--r--lib/chef/provider/package/smartos.rb1
-rw-r--r--lib/chef/provider/package/snap.rb4
-rw-r--r--lib/chef/provider/package/solaris.rb2
-rw-r--r--lib/chef/provider/package/windows/msi.rb1
-rw-r--r--lib/chef/provider/package/windows/registry_uninstall_entry.rb1
-rw-r--r--lib/chef/provider/package/yum.rb3
-rw-r--r--lib/chef/provider/package/yum/python_helper.rb1
19 files changed, 32 insertions, 0 deletions
diff --git a/lib/chef/provider/package/apt.rb b/lib/chef/provider/package/apt.rb
index cd28746411..b8f2356811 100644
--- a/lib/chef/provider/package/apt.rb
+++ b/lib/chef/provider/package/apt.rb
@@ -134,6 +134,7 @@ class Chef
# @return [Boolean] if apt-get supports --allow-downgrades
def supports_allow_downgrade?
return @supports_allow_downgrade unless @supports_allow_downgrade.nil?
+
@supports_allow_downgrade = ( version_compare(apt_version, "1.1.0") >= 0 )
end
@@ -194,6 +195,7 @@ class Chef
showpkg = run_noninteractive("apt-cache", "showpkg", pkg).stdout
partitions = showpkg.rpartition(/Reverse Provides: ?#{$/}/)
return nil if partitions[0] == "" && partitions[1] == "" # not found in output
+
set = partitions[2].lines.each_with_object(Set.new) do |line, acc|
# there may be multiple reverse provides for a single package
acc.add(line.split[0])
@@ -201,6 +203,7 @@ class Chef
if set.size > 1
raise Chef::Exceptions::Package, "#{new_resource.package_name} is a virtual package provided by multiple packages, you must explicitly select one"
end
+
set.to_a.first
end
diff --git a/lib/chef/provider/package/bff.rb b/lib/chef/provider/package/bff.rb
index b0a89454b5..0b358dcb46 100644
--- a/lib/chef/provider/package/bff.rb
+++ b/lib/chef/provider/package/bff.rb
@@ -84,6 +84,7 @@ class Chef
def candidate_version
return @candidate_version if @candidate_version
+
if package_source_found?
ret = shell_out("installp", "-L", "-d", new_resource.source)
ret.stdout.each_line do |line|
diff --git a/lib/chef/provider/package/cab.rb b/lib/chef/provider/package/cab.rb
index 9b2aaa048f..c98e135868 100644
--- a/lib/chef/provider/package/cab.rb
+++ b/lib/chef/provider/package/cab.rb
@@ -78,6 +78,7 @@ class Chef
result = shell_out("dism.exe /Online /English #{command} /NoRestart", { timeout: new_resource.timeout })
if result.exitstatus == -2146498530
raise Chef::Exceptions::Package, "The specified package is not applicable to this image." if result.stdout.include?("0x800f081e")
+
result.error!
end
result
@@ -127,6 +128,7 @@ class Chef
text.each_line do |line|
key, value = line.split(":") if line.start_with?("Package Identity")
next if key.nil? || value.nil?
+
package = {}
package[key.downcase.strip.tr(" ", "_")] = value.strip.chomp
packages << package
diff --git a/lib/chef/provider/package/chocolatey.rb b/lib/chef/provider/package/chocolatey.rb
index a7e6096cd6..98cb57cb79 100644
--- a/lib/chef/provider/package/chocolatey.rb
+++ b/lib/chef/provider/package/chocolatey.rb
@@ -154,6 +154,7 @@ class Chef
# run before choco.exe gets called from #load_current_resource.
exe_path = ::File.join(choco_install_path.to_s, "bin", "choco.exe")
raise Chef::Exceptions::MissingLibrary, CHOCO_MISSING_MSG unless ::File.exist?(exe_path)
+
exe_path
end
end
@@ -230,6 +231,7 @@ class Chef
# @return [Hash] name-to-version mapping of available packages
def available_packages
return @available_packages if @available_packages
+
@available_packages = {}
package_name_array.each do |pkg|
available_versions =
@@ -266,6 +268,7 @@ class Chef
hash = {}
choco_command(*args).stdout.each_line do |line|
next if line.start_with?("Chocolatey v")
+
name, version = line.split("|")
hash[name.downcase] = version&.chomp
end
diff --git a/lib/chef/provider/package/dnf/python_helper.rb b/lib/chef/provider/package/dnf/python_helper.rb
index 881c852392..c5edbfbc3a 100644
--- a/lib/chef/provider/package/dnf/python_helper.rb
+++ b/lib/chef/provider/package/dnf/python_helper.rb
@@ -161,6 +161,7 @@ class Chef
retry
else
raise e if output.empty?
+
raise "dnf-helper.py had stderr output:\n\n#{output}"
end
end
diff --git a/lib/chef/provider/package/freebsd/base.rb b/lib/chef/provider/package/freebsd/base.rb
index 7c1b244283..bfd828552c 100644
--- a/lib/chef/provider/package/freebsd/base.rb
+++ b/lib/chef/provider/package/freebsd/base.rb
@@ -51,6 +51,7 @@ class Chef
unless path = whereis.stdout[/^#{Regexp.escape(port)}:\s+(.+)$/, 1]
raise Chef::Exceptions::Package, "Could not find port with the name #{port}"
end
+
path
end
end
diff --git a/lib/chef/provider/package/macports.rb b/lib/chef/provider/package/macports.rb
index 384435778d..1d0bfa9984 100644
--- a/lib/chef/provider/package/macports.rb
+++ b/lib/chef/provider/package/macports.rb
@@ -93,6 +93,7 @@ class Chef
unless status.exitstatus == 0 || status.exitstatus == 1
raise Chef::Exceptions::Package, "#{command} failed - #{status.inspect}!"
end
+
output
end
end
diff --git a/lib/chef/provider/package/msu.rb b/lib/chef/provider/package/msu.rb
index 073d3f6454..0f2dca1290 100644
--- a/lib/chef/provider/package/msu.rb
+++ b/lib/chef/provider/package/msu.rb
@@ -54,6 +54,7 @@ class Chef
else
current_resource.version(get_current_versions)
end
+
current_resource
end
@@ -148,6 +149,7 @@ class Chef
cab_files
end
+
cab_files
end
diff --git a/lib/chef/provider/package/paludis.rb b/lib/chef/provider/package/paludis.rb
index 27854f31be..3fd526abe4 100644
--- a/lib/chef/provider/package/paludis.rb
+++ b/lib/chef/provider/package/paludis.rb
@@ -38,6 +38,7 @@ class Chef
shell_out!("cave", "-L", "warning", "print-ids", "-M", "none", "-m", new_resource.package_name, "-f", "%c/%p %v %r\n").stdout.each_line do |line|
res = re.match(line)
next if res.nil?
+
case res[3]
when "accounts", "installed-accounts"
next
diff --git a/lib/chef/provider/package/powershell.rb b/lib/chef/provider/package/powershell.rb
index 7901569532..c10150a32c 100644
--- a/lib/chef/provider/package/powershell.rb
+++ b/lib/chef/provider/package/powershell.rb
@@ -39,6 +39,7 @@ class Chef
if powershell_out("$PSVersionTable.PSVersion.Major").stdout.strip.to_i < 5
raise "Minimum installed PowerShell Version required is 5"
end
+
requirements.assert(: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(', ')}")
diff --git a/lib/chef/provider/package/rpm.rb b/lib/chef/provider/package/rpm.rb
index 45dbf91061..75b41a26e4 100644
--- a/lib/chef/provider/package/rpm.rb
+++ b/lib/chef/provider/package/rpm.rb
@@ -116,6 +116,7 @@ class Chef
def uri_scheme?(str)
scheme = URI.split(str).first
return false unless scheme
+
%w{http https ftp file}.include?(scheme.downcase)
rescue URI::InvalidURIError
false
diff --git a/lib/chef/provider/package/rubygems.rb b/lib/chef/provider/package/rubygems.rb
index 8179deceed..1980629da1 100644
--- a/lib/chef/provider/package/rubygems.rb
+++ b/lib/chef/provider/package/rubygems.rb
@@ -444,6 +444,7 @@ class Chef
def source_is_remote?
return true if new_resource.source.nil?
return true if new_resource.source.is_a?(Array)
+
scheme = URI.parse(new_resource.source).scheme
# URI.parse gets confused by MS Windows paths with forward slashes.
scheme = nil if scheme =~ /^[a-z]$/
@@ -516,6 +517,7 @@ class Chef
def version_requirement_satisfied?(current_version, new_version)
return false unless current_version && new_version
+
Gem::Requirement.new(new_version).satisfied_by?(Gem::Version.new(current_version))
end
diff --git a/lib/chef/provider/package/smartos.rb b/lib/chef/provider/package/smartos.rb
index be1e6f81a3..a44280ec75 100644
--- a/lib/chef/provider/package/smartos.rb
+++ b/lib/chef/provider/package/smartos.rb
@@ -56,6 +56,7 @@ class Chef
def candidate_version
return @candidate_version if @candidate_version
+
name = nil
version = nil
pkg = shell_out!("/opt/local/bin/pkgin", "se", new_resource.package_name, env: nil, returns: [0, 1])
diff --git a/lib/chef/provider/package/snap.rb b/lib/chef/provider/package/snap.rb
index 8096f54659..c9f9e1134f 100644
--- a/lib/chef/provider/package/snap.rb
+++ b/lib/chef/provider/package/snap.rb
@@ -154,6 +154,7 @@ class Chef
if response["type"] == "error"
raise "status: #{response["status"]}, kind: #{response["result"]["kind"]}, message: #{response["result"]["message"]}"
end
+
response["change"]
end
@@ -177,6 +178,7 @@ class Chef
end
n += 1
raise "Snap operating timed out after #{n} seconds." if n == 300
+
sleep(1)
end
end
@@ -319,6 +321,7 @@ class Chef
unless [200, 404].include? json["status-code"]
raise Chef::Exceptions::Package, json["result"], caller
end
+
json["result"]
end
@@ -338,6 +341,7 @@ class Chef
unless [200, 404].include? json["status-code"]
raise Chef::Exceptions::Package, json["result"], caller
end
+
json["result"]
end
diff --git a/lib/chef/provider/package/solaris.rb b/lib/chef/provider/package/solaris.rb
index d30e783a1e..fb0e88ecdb 100644
--- a/lib/chef/provider/package/solaris.rb
+++ b/lib/chef/provider/package/solaris.rb
@@ -83,6 +83,7 @@ class Chef
def candidate_version
return @candidate_version if @candidate_version
+
status = shell_out("pkginfo", "-l", "-d", new_resource.source, new_resource.package_name)
status.stdout.each_line do |line|
case line
@@ -95,6 +96,7 @@ class Chef
unless status.exitstatus == 0
raise Chef::Exceptions::Package, "pkginfo -l -d #{new_resource.source} - #{status.inspect}!"
end
+
@candidate_version
end
diff --git a/lib/chef/provider/package/windows/msi.rb b/lib/chef/provider/package/windows/msi.rb
index 870aff6865..c034d9d31b 100644
--- a/lib/chef/provider/package/windows/msi.rb
+++ b/lib/chef/provider/package/windows/msi.rb
@@ -60,6 +60,7 @@ class Chef
def package_version
return new_resource.version if new_resource.version
+
if !new_resource.source.nil? && ::File.exist?(new_resource.source)
logger.trace("#{new_resource} getting product version for package at #{new_resource.source}")
get_product_property(new_resource.source, "ProductVersion")
diff --git a/lib/chef/provider/package/windows/registry_uninstall_entry.rb b/lib/chef/provider/package/windows/registry_uninstall_entry.rb
index d57f700799..6f8f359894 100644
--- a/lib/chef/provider/package/windows/registry_uninstall_entry.rb
+++ b/lib/chef/provider/package/windows/registry_uninstall_entry.rb
@@ -58,6 +58,7 @@ class Chef
def self.quiet_uninstall_string_key?(quiet_uninstall_string, hkey, key, entry)
return RegistryUninstallEntry.new(hkey, key, entry) if quiet_uninstall_string.nil?
+
RegistryUninstallEntry.new(hkey, key, entry, "QuietUninstallString")
end
diff --git a/lib/chef/provider/package/yum.rb b/lib/chef/provider/package/yum.rb
index 74343fa10d..08a9c857c9 100644
--- a/lib/chef/provider/package/yum.rb
+++ b/lib/chef/provider/package/yum.rb
@@ -186,16 +186,19 @@ class Chef
def version_gt?(v1, v2)
return false if v1.nil? || v2.nil?
+
python_helper.compare_versions(v1, v2) == 1
end
def version_equals?(v1, v2)
return false if v1.nil? || v2.nil?
+
python_helper.compare_versions(v1, v2) == 0
end
def version_compare(v1, v2)
return false if v1.nil? || v2.nil?
+
python_helper.compare_versions(v1, v2)
end
diff --git a/lib/chef/provider/package/yum/python_helper.rb b/lib/chef/provider/package/yum/python_helper.rb
index ee7f64d1ea..af0f25bea9 100644
--- a/lib/chef/provider/package/yum/python_helper.rb
+++ b/lib/chef/provider/package/yum/python_helper.rb
@@ -212,6 +212,7 @@ class Chef
retry
else
raise e if output.empty?
+
raise "yum-helper.py had stderr/stdout output:\n\n#{output}"
end
end