From 22e7d93378ef6bea0f3ee74d69f36737a1dcae25 Mon Sep 17 00:00:00 2001 From: Christopher Thorn Date: Tue, 9 Jul 2024 13:04:12 -0700 Subject: [PATCH] (PA-5807) Ignore yumrepo files managed by Puppet file resource Previously we attempted to manage every repo that was found in the yumrepos directory. If one of those repos was a Puppet File resource, yumrepo would manage the yumrepo the Puppet File resource was creating. This casued some idepontecy issues. This change will make it so yumrepo will not attempt to manage any file resource it finds that is found in the yumrepo directory. --- lib/puppet/provider/yumrepo/inifile.rb | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/puppet/provider/yumrepo/inifile.rb b/lib/puppet/provider/yumrepo/inifile.rb index 026e562..2f18848 100644 --- a/lib/puppet/provider/yumrepo/inifile.rb +++ b/lib/puppet/provider/yumrepo/inifile.rb @@ -82,10 +82,10 @@ def new_physical_file(file) # @api public # @return [Array] providers generated from existing yum # repository definitions. - def self.instances + def self.instances(resources = nil) instances = [] - virtual_inifile.each_section do |section| + virtual_inifile(resources).each_section do |section| # Ignore the 'main' section in yum.conf since it's not a repository. next if section.name == 'main' @@ -111,7 +111,7 @@ def self.instances # @param resources [Array] Resources to prefetch. # @return [void] def self.prefetch(resources) - repos = instances + repos = instances(resources) resources.each_key do |name| provider = repos.find { |repo| repo.name == name } if provider @@ -182,14 +182,27 @@ def self.repofiles # Build a virtual inifile by reading in numerous .repo files into a single # virtual file to ease manipulation. + # Will skip any inifile that is found to be currently managed as a file resource + # in the catalog. # @api private # @return [Puppet::Provider::Yumrepo::IniConfig::File] The virtual inifile representing # multiple real files. - def self.virtual_inifile + def self.virtual_inifile(resources = nil) + current_yumrepo_inis = [] + resources&.each do |key| + current_yumrepo_inis << key[1] + end + unless @virtual @virtual = Puppet::Provider::Yumrepo::IniConfig::File.new repofiles.each do |file| - @virtual.read(file) if Puppet::FileSystem.file?(file) + index_virtual = true + unless current_yumrepo_inis.empty? + current_yumrepo_inis.each do |index| + index_virtual = false if index.catalog.resource('File', file) + end + end + @virtual.read(file) if Puppet::FileSystem.file?(file) && index_virtual end end @virtual