From c0a5fca7d44d492b5551141ae99640ce86c6da78 Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Wed, 10 Jan 2024 12:38:07 +0100 Subject: [PATCH] Copy the mtime on puppet generate types When installing a new module it can maintain the file timestamps from the original tarball (like g10 does). puppet generate types uses the timestamp of when it ran. If you update a module to a release that was created before it ran puppet types generate, it will never update the types. This can happen with a module downgrade, or just when you regenerated types manually. By using --force the timestamps are ignored, but that's only a workaround. This new approach copies the mtime from the source file to the generated cache file. It is only considered up to date if the mtime matches. --- lib/puppet/generate/type.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/puppet/generate/type.rb b/lib/puppet/generate/type.rb index 1bb066bfdde..698b7416669 100644 --- a/lib/puppet/generate/type.rb +++ b/lib/puppet/generate/type.rb @@ -49,7 +49,7 @@ def format=(format) # @return [Boolean] Returns true if the output is up-to-date or false if not. def up_to_date?(outputdir) f = effective_output_path(outputdir) - Puppet::FileSystem::exist?(f) && (Puppet::FileSystem::stat(@path) <=> Puppet::FileSystem::stat(f)) <= 0 + Puppet::FileSystem::exist?(f) && (Puppet::FileSystem::stat(@path) <=> Puppet::FileSystem::stat(f)) == 0 end # Gets the filename of the output file. @@ -240,6 +240,7 @@ def self.generate(inputs, outputdir = nil, force = false) Puppet::FileSystem.open(effective_output_path, nil, 'w:UTF-8') do |file| file.write(result) end + Puppet::FileSystem.touch(effective_output_path, mtime: Puppet::FileSystem::stat(input.path).mtime) rescue Exception => e @bad_input = true Puppet.log_exception(e, _("Failed to generate '%{effective_output_path}': %{message}") % { effective_output_path: effective_output_path, message: e.message })