Skip to content

Commit

Permalink
Copy the mtime on puppet generate types
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ekohl committed Jan 12, 2024
1 parent 97f7854 commit c0a5fca
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/puppet/generate/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 })
Expand Down

0 comments on commit c0a5fca

Please sign in to comment.