Skip to content

Commit

Permalink
(PA-5807) Ignore yumrepo files managed by Puppet file resource
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cthorn42 committed Jul 23, 2024
1 parent 5af405b commit 22e7d93
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions lib/puppet/provider/yumrepo/inifile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ def new_physical_file(file)
# @api public
# @return [Array<Puppet::Provider>] 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'

Expand All @@ -111,7 +111,7 @@ def self.instances
# @param resources [Array<Puppet::Type::Yumrepo>] 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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 22e7d93

Please sign in to comment.