Skip to content

Commit ac6d139

Browse files
committed
(PUP-11597) A working, but very likely not ideal fix for PUP-11597
1 parent dfe10b2 commit ac6d139

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

lib/puppet/generate/type.rb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,24 @@ def format=(format)
4646
# @return [Boolean] Returns true if the output is up-to-date or false if not.
4747
def up_to_date?(outputdir)
4848
f = effective_output_path(outputdir)
49-
Puppet::FileSystem::exist?(f) && (Puppet::FileSystem::stat(@path) <=> Puppet::FileSystem::stat(f)) <= 0
49+
# Check the fast-path scenarios first.
50+
unless Puppet::FileSystem::exist?(f)
51+
Puppet.debug("#{f} does not exist.")
52+
return false
53+
end
54+
unless (Puppet::FileSystem::stat(@path) <=> Puppet::FileSystem::stat(f)) <= 0
55+
Puppet.debug("#{@path} is newer than #{f}")
56+
return false
57+
end
58+
# Check for updates to any module lib files.
59+
module_lib_files = Dir.glob(@base + "/lib/**/*.rb")
60+
module_lib_files.each do |lib|
61+
unless (Puppet::FileSystem::stat(lib) <=> Puppet::FileSystem::stat(f)) <= 0
62+
Puppet.debug("#{lib} is newer than #{f}")
63+
return false
64+
end
65+
end
66+
return true
5067
end
5168

5269
# Gets the filename of the output file.

spec/unit/face/generate_spec.rb

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ module Puppet
6666
} }
6767
},
6868
},
69-
'm2' => {
69+
'm2' => {
7070
'lib' => { 'puppet' => { 'type' => {
7171
'test2.rb' => <<-EOF
7272
module Puppet
@@ -184,9 +184,7 @@ module Puppet
184184
# create them (first run)
185185
genface.types
186186
stats_before = [Puppet::FileSystem.stat(File.join(outputdir, 'test1.pp')), Puppet::FileSystem.stat(File.join(outputdir, 'test2.pp'))]
187-
# fake change in input test1 - sorry about the sleep (which there was a better way to change the modtime
188-
sleep(1)
189-
Puppet::FileSystem.touch(File.join(m1, 'lib', 'puppet', 'type', 'test1.rb'))
187+
Puppet::FileSystem.touch(File.join(m1, 'lib', 'puppet', 'type', 'test1.rb'), :mtime => Time.now + 10)
190188
# generate again
191189
genface.types
192190
# assert that test1 was overwritten (later) but not test2 (same time)
@@ -199,8 +197,7 @@ module Puppet
199197
# create them (first run)
200198
genface.types
201199
stats_before = [Puppet::FileSystem.stat(File.join(outputdir, 'test1.pp')), Puppet::FileSystem.stat(File.join(outputdir, 'test2.pp'))]
202-
# generate again
203-
sleep(1) # sorry, if there is no delay the stats will be the same
200+
Puppet::FileSystem.touch(File.join(outputdir, 'test2.pp'), :mtime => Time.now + 10)
204201
genface.types(:force => true)
205202
stats_after = [Puppet::FileSystem.stat(File.join(outputdir, 'test1.pp')), Puppet::FileSystem.stat(File.join(outputdir, 'test2.pp'))]
206203
expect(stats_before <=> stats_after).to be(-1)
@@ -220,6 +217,18 @@ module Puppet
220217
expect(stat_before <=> stats_after).to be(0)
221218
end
222219

220+
it 'overwrites if ruby files in lib/puppet_x/ are updated' do
221+
# create them (first run)
222+
puppet_x_lib = File.join(m1, 'lib', 'puppet_x', 'foo', 'library.rb')
223+
Puppet::FileSystem.mkpath(puppet_x_lib)
224+
genface.types
225+
stat_before = Puppet::FileSystem.stat(File.join(outputdir, 'test1.pp'))
226+
Puppet::FileSystem.touch(puppet_x_lib, :mtime => Time.now + 10)
227+
genface.types
228+
stat_after = Puppet::FileSystem.stat(File.join(outputdir, 'test1.pp'))
229+
expect(stat_before <=> stat_after).to be(-1)
230+
end
231+
223232
end
224233

225234
context "in an environment with a faulty type" do

0 commit comments

Comments
 (0)