diff options
Diffstat (limited to 'lib/chef/provider')
-rw-r--r-- | lib/chef/provider/package.rb | 25 | ||||
-rw-r--r-- | lib/chef/provider/package/apt.rb | 8 | ||||
-rw-r--r-- | lib/chef/provider/package/zypper.rb | 21 |
3 files changed, 19 insertions, 35 deletions
diff --git a/lib/chef/provider/package.rb b/lib/chef/provider/package.rb index 5d2c85bcfe..0f1adfb3d0 100644 --- a/lib/chef/provider/package.rb +++ b/lib/chef/provider/package.rb @@ -218,25 +218,12 @@ class Chef end end - def package_locked? - if !current_version_array.any? - # ! any? means it's all nil's, which means nothing is installed - false - elsif !new_version_array.any? - true # remove any version of all packages - elsif have_any_matching_version? - true # remove the version we have - else - false # we don't have the version we want to remove - end - end - def action_lock multipackage_api_adapter(@current_resource.package_name, @new_resource.version) do |name, version| - if package_locked(name) == true + if package_locked(name, version) == true Chef::Log.debug("#{new_resource} is already locked") else - lock_package(name) + lock_package(name, version) Chef::Log.info("#{@new_resource} locked") end end @@ -244,10 +231,10 @@ class Chef def action_unlock multipackage_api_adapter(@current_resource.package_name, @new_resource.version) do |name, version| - if package_locked(name) == false + if package_locked(name, version) == false Chef::Log.debug("#{new_resource} is already unlocked") else - unlock_package(name) + unlock_package(name, version) Chef::Log.info("#{@new_resource} unlocked") end end @@ -287,11 +274,11 @@ class Chef raise( Chef::Exceptions::UnsupportedAction, "#{self} does not support :reconfig" ) end - def lock_package(name) + def lock_package(name, version) raise( Chef::Exceptions::UnsupportedAction, "#{self} does not support :lock" ) end - def unlock_package(name) + def unlock_package(name, version) raise( Chef::Exceptions::UnsupportedAction, "#{self} does not support :unlock" ) end diff --git a/lib/chef/provider/package/apt.rb b/lib/chef/provider/package/apt.rb index 8af089e14a..13186097f4 100644 --- a/lib/chef/provider/package/apt.rb +++ b/lib/chef/provider/package/apt.rb @@ -105,6 +105,14 @@ class Chef run_noninteractive("dpkg-reconfigure", name) end + def lock_package(name, version) + run_noninteractive("apt-mark -q -y", new_resource.options, "hold", name) + end + + def unlock_package(name, version) + run_noninteractive("apt-mark -q -y", new_resource.options, "unhold", name) + end + private # Runs command via shell_out with magic environment to disable diff --git a/lib/chef/provider/package/zypper.rb b/lib/chef/provider/package/zypper.rb index efe07f52af..5b5cd0d71c 100644 --- a/lib/chef/provider/package/zypper.rb +++ b/lib/chef/provider/package/zypper.rb @@ -75,18 +75,7 @@ class Chef end end -### def package_locked? -### package_name_array.map do |package_name| -#### lock = `zypper locks | grep "| #{package_name} "`.split("|").shift(2).last.strip -### package_name.lock = `zypper locks | grep "| #{package_name} "` -### if package_name.lock.empty? -### false -### else -### true -### end -### end -### end - def package_locked(name) + def package_locked(name, version) islocked = false locked = shell_out_with_timeout!("zypper locks") locked.stdout.each_line do |line| @@ -129,12 +118,12 @@ class Chef zypper_package("remove --clean-deps", name, version) end - def lock_package(name) - shell_out_with_timeout!(a_to_s("zypper", "addlock", name)) + def lock_package(name, version) + zypper_package("addlock", name, version) end - def unlock_package(name) - shell_out_with_timeout!(a_to_s("zypper", "removelock", name)) + def unlock_package(name, version) + zypper_package("removelock", name, version) end private |