]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Plugin/aggregate.pm
* aggregate: Fork a child process to handle the aggregation. This simplifies
[ikiwiki.git] / IkiWiki / Plugin / aggregate.pm
index 0da527f25e7bff733b0f64473e6fc7f67d323982..09ea5902938b16030ab75ced886288a4e5497454 100644 (file)
@@ -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};