Clean up regeneration missing-destination checks

Use easier-to-follow checks for missing-destinations in the regenerator.
This commit is contained in:
Nicholas Burlett 2015-03-24 21:21:37 -07:00
parent 706007ead9
commit 8f4194eea5
2 changed files with 16 additions and 17 deletions

View File

@ -18,21 +18,19 @@ module Jekyll
def regenerate?(document) def regenerate?(document)
case document case document
when Post, Page when Post, Page
return ( document.asset_file? || document.asset_file? || document.data['regenerate'] ||
document.data['regenerate'] || source_modified_or_dest_missing?(
source_modified_or_dest_missing?( site.in_source_dir(document.relative_path), document.destination(@site.dest)
site.in_source_dir(document.relative_path), )
document.destination(@site.dest)) )
when Document when Document
return ( !document.write? || !document.write? || document.data['regenerate'] ||
document.data['regenerate'] || source_modified_or_dest_missing?(
source_modified_or_dest_missing?( document.path, document.destination(@site.dest)
document.path, )
document.destination(@site.dest)) )
else else
source_path = document.respond_to?(:path) ? document.path : nil source_path = document.respond_to?(:path) ? document.path : nil
dest_path = document.respond_to?(:destination) ? document.destination(@site.dest) : nil dest_path = document.respond_to?(:destination) ? document.destination(@site.dest) : nil
return source_modified_or_dest_missing?(source_path, dest_path) source_modified_or_dest_missing?(source_path, dest_path)
end end
end end
@ -78,9 +76,7 @@ module Jekyll
# #
# returns a boolean # returns a boolean
def source_modified_or_dest_missing?(source_path, dest_path) def source_modified_or_dest_missing?(source_path, dest_path)
source_modified = source_path ? modified?(source_path) : true modified?(source_path) || ((dest_path and !File.exist?(dest_path)) or false)
dest_missing = dest_path ? !File.exist?(dest_path) : false
return source_modified || dest_missing
end end
# Checks if a path's (or one of its dependencies) # Checks if a path's (or one of its dependencies)
@ -90,6 +86,9 @@ module Jekyll
def modified?(path) def modified?(path)
return true if disabled? return true if disabled?
# objects that don't have a path are always regenerated
return true if path.nil?
# Check for path in cache # Check for path in cache
if cache.has_key? path if cache.has_key? path
return cache[path] return cache[path]

View File

@ -505,11 +505,11 @@ class TestSite < JekyllUnitTest
# simulate file modification by user # simulate file modification by user
File.unlink dest File.unlink dest
refute File.exist?(dest) refute File.file?(dest)
sleep 1 sleep 1 # sleep for 1 second, since mtimes have 1s resolution
@site.process @site.process
assert File.exist?(dest) assert File.file?(dest)
mtime2 = File.stat(dest).mtime.to_i mtime2 = File.stat(dest).mtime.to_i
refute_equal mtime1, mtime2 # must be regenerated refute_equal mtime1, mtime2 # must be regenerated
end end