From 378b450b8dd1d342bf6ea2e3c25e5777b21d78b5 Mon Sep 17 00:00:00 2001 From: Bryan Jen Date: Thu, 9 Jun 2016 16:16:23 -0700 Subject: [PATCH] (maint) Syncs up file_concat with concat --- README.md | 23 ----------------- lib/puppet/type/file_concat.rb | 47 +++++++++++++++++++++++----------- 2 files changed, 32 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index 4cdcc07..17a6b46 100644 --- a/README.md +++ b/README.md @@ -50,28 +50,5 @@ example: ## Limitations -A bug where module will be unable to build correct dependency graph if the manifest contains a resource to recursively purge a parent directory. - -Example: [MODULES-2054](https://tickets.puppetlabs.com/browse/MODULES-2054) -~~~ -file { '/tmp/bug': - ensure => directory, - purge => true, - recurse => true, - force => true -} - -file_concat { 'test' : - path => '/tmp/bug/tester', - tag => 'mytag', - require => File['/tmp/bug'] -} - -file_fragment { 'test-1': - tag => 'mytag', - content => 'test' -} -~~~ - ## Development diff --git a/lib/puppet/type/file_concat.rb b/lib/puppet/type/file_concat.rb index 90da7ab..c562bbe 100644 --- a/lib/puppet/type/file_concat.rb +++ b/lib/puppet/type/file_concat.rb @@ -112,12 +112,9 @@ def decompound(d) decompound(a[0]) <=> decompound(b[0]) end else - sorted = content_fragments.sort do |a, b| - def decompound(d) - d.split('___').first - end - - decompound(a[0]) <=> decompound(b[0]) + sorted = content_fragments.sort_by do |a| + a_order, a_name = a[0].split('__') + [a_order, a_name] end end @@ -149,19 +146,39 @@ def fragment_content(r) fragment_content end - def eval_generate - content = self.should_content + def generate + file_opts = { + :ensure => self[:ensure] == :absent ? :absent : :file, + } - file_opts = {} - file_opts[:ensure] = self[:ensure] == :absent ? :absent : :file - file_opts[:content] = content if !content.nil? and !content.empty? + [:path, + :owner, + :group, + :mode, + :replace, + :backup, + :validate_cmd, + end - [:path, :owner, :group, :mode, :replace, :backup].each do |param| - unless self[param].nil? - file_opts[param] = self[param] - end + metaparams = Puppet::Type.metaparams + excluded_metaparams = [ :before, :notify, :require, :subscribe, :tag ] + + metaparams.reject! { |param| excluded_metaparams.include? param } + + metaparams.each do |metaparam| + file_opts[metaparam] = self[metaparam] if self[metaparam] end [Puppet::Type.type(:file).new(file_opts)] end + + def eval_generate + content = self.should_content + + if !content.nil? and !content.empty? + catalog.resource("File[#{self[:path]}]")[:content] = content + end + + [ catalog.resource("File[#{self[:path]}]") ] + end end