summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet')
-rwxr-xr-xlib/puppet/provider/package/yum.rb41
1 files changed, 24 insertions, 17 deletions
diff --git a/lib/puppet/provider/package/yum.rb b/lib/puppet/provider/package/yum.rb
index 7998b92c0..56fad1af9 100755
--- a/lib/puppet/provider/package/yum.rb
+++ b/lib/puppet/provider/package/yum.rb
@@ -7,9 +7,7 @@ Puppet::Type.type(:package).provide :yum, :parent => :rpm, :source => :rpm do
YUMHELPER = File::join(File::dirname(__FILE__), "yumhelper.py")
- class << self
- attr_reader :updates
- end
+ attr_accessor :latest_info
if command('rpm')
confine :true => begin
@@ -24,22 +22,32 @@ Puppet::Type.type(:package).provide :yum, :parent => :rpm, :source => :rpm do
defaultfor :operatingsystem => [:fedora, :centos, :redhat]
def self.prefetch(packages)
- @updates = {}
if Process.euid != 0
raise Puppet::Error, "The yum provider can only be used as root"
end
super
- python(YUMHELPER).each_line do |l|
- l.chomp!
- next if l.empty?
- if l[0,4] == "_pkg"
- hash = nevra_to_hash(l[5..-1])
- [hash[:name], "#{hash[:name]}.#{hash[:arch]}"].each do |n|
- @updates[n] ||= []
- @updates[n] << hash
- end
- end
- end
+ return unless packages.detect { |name, package| package.should(:ensure) == :latest }
+
+ # collect our 'latest' info
+ updates = {}
+ python(YUMHELPER).each_line do |l|
+ l.chomp!
+ next if l.empty?
+ if l[0,4] == "_pkg"
+ hash = nevra_to_hash(l[5..-1])
+ [hash[:name], "#{hash[:name]}.#{hash[:arch]}"].each do |n|
+ updates[n] ||= []
+ updates[n] << hash
+ end
+ end
+ end
+
+ # Add our 'latest' info to the providers.
+ packages.each do |name, package|
+ if info = updates[package[:name]]
+ package.provider.latest_info = info[0]
+ end
+ end
end
def install
@@ -73,11 +81,10 @@ Puppet::Type.type(:package).provide :yum, :parent => :rpm, :source => :rpm do
# What's the latest package version available?
def latest
- upd = self.class.updates[@resource[:name]]
+ upd = latest_info
unless upd.nil?
# FIXME: there could be more than one update for a package
# because of multiarch
- upd = upd[0]
return "#{upd[:version]}-#{upd[:release]}"
else
# Yum didn't find updates, pretend the current