X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/dc16e386819da912a5fa37214a0d1335cc4d97f5..3d9468d5e75d9de33f299cbaae5c5862fa48a801:/IkiWiki/Plugin/aggregate.pm

diff --git a/IkiWiki/Plugin/aggregate.pm b/IkiWiki/Plugin/aggregate.pm
index a2c10ce5c..71368e254 100644
--- a/IkiWiki/Plugin/aggregate.pm
+++ b/IkiWiki/Plugin/aggregate.pm
@@ -37,14 +37,25 @@ sub checkconfig () { #{{{
 			debug("wiki is locked by another process, not aggregating");
 			exit 1;
 		}
-	
-		loadstate();
-		IkiWiki::loadindex();
-		aggregate();
-		expire();
-		savestate();
-		clearstate();
-
+		
+		# Fork a child process to handle the aggregation.
+		# The parent process will then handle building the result.
+		# This avoids messy code to clear state accumulated while
+		# aggregating.
+		defined(my $pid = fork) or error("Can't fork: $!");
+		if (! $pid) {
+			loadstate();
+			IkiWiki::loadindex();
+			aggregate();
+			expire();
+			savestate();
+			exit 0;
+		}
+		waitpid($pid,0);
+		if ($?) {
+			error "aggregation failed with code $?";
+		}
+		
 		IkiWiki::unlockwiki();
 	}
 } #}}}
@@ -211,12 +222,6 @@ sub savestate () { #{{{
 		error("rename $newfile: $!", $cleanup);
 } #}}}
 
-sub clearstate () { #{{{
-	%feeds=();
-	%guids=();
-	$state_loaded=0;
-} #}}}
-
 sub expire () { #{{{
 	foreach my $feed (values %feeds) {
 		next unless $feed->{expireage} || $feed->{expirecount};
@@ -416,7 +421,8 @@ sub add_page (@) { #{{{
 
 	# Set the mtime, this lets the build process get the right creation
 	# time on record for the new page.
-	utime $mtime, $mtime, pagefile($guid->{page}) if defined $mtime;
+	utime $mtime, $mtime, pagefile($guid->{page})
+		if defined $mtime && $mtime <= time;
 } #}}}
 
 sub htmlescape ($) { #{{{