]> sipb.mit.edu Git - ikiwiki.git/commitdiff
add aggregate locking functions
authorJoey Hess <joey@kodama.kitenet.net>
Sun, 3 Feb 2008 20:17:15 +0000 (15:17 -0500)
committerJoey Hess <joey@kodama.kitenet.net>
Sun, 3 Feb 2008 20:17:15 +0000 (15:17 -0500)
IkiWiki/Plugin/aggregate.pm

index 0f50fab06c6795154bff70786459a3ff474464d8..cfc4ec955328e2dfa812b04b4cacd683ba336884 100644 (file)
@@ -495,4 +495,26 @@ sub htmlfn ($) { #{{{
        return shift().".".$config{htmlext};
 } #}}}
 
+my $aggregatelock;
+
+sub lockaggregate () { #{{{
+       # Take an exclusive lock to prevent multiple concurrent aggregators.
+       # Returns true if the lock was aquired.
+       if (! -d $config{wikistatedir}) {
+               mkdir($config{wikistatedir});
+       }
+       open($aggregatelock, '>', "$config{wikistatedir}/aggregatelock") ||
+               error ("cannot open to $config{wikistatedir}/aggregatelock: $!");
+       if (! flock($aggregatelock, 2 | 4)) { # LOCK_EX | LOCK_NB
+               close($aggregatelock) || error("failed closing aggregatelock: $!");
+               return 0;
+       }
+       return 1;
+} #}}}
+
+sub unlockaggregate () { #{{{
+       return close($aggregatelock) if $aggregatelock;
+       return;
+} #}}}
+
 1