aboutsummaryrefslogtreecommitdiff
path: root/IkiWiki
diff options
context:
space:
mode:
authorJoey Hess <joey@kodama.kitenet.net>2008-02-03 15:17:15 -0500
committerJoey Hess <joey@kodama.kitenet.net>2008-02-03 15:17:15 -0500
commit38affb0c1c4e2b89beb63d6f8dc3f172eee7bd02 (patch)
tree25bfdcc6c8553acd5259bc77e7443542d9e80539 /IkiWiki
parentd8d2b316928e04d95f3abd4c392ba44403837837 (diff)
downloadikiwiki-38affb0c1c4e2b89beb63d6f8dc3f172eee7bd02.tar
ikiwiki-38affb0c1c4e2b89beb63d6f8dc3f172eee7bd02.tar.gz
add aggregate locking functions
Diffstat (limited to 'IkiWiki')
-rw-r--r--IkiWiki/Plugin/aggregate.pm22
1 files changed, 22 insertions, 0 deletions
diff --git a/IkiWiki/Plugin/aggregate.pm b/IkiWiki/Plugin/aggregate.pm
index 0f50fab06..cfc4ec955 100644
--- a/IkiWiki/Plugin/aggregate.pm
+++ b/IkiWiki/Plugin/aggregate.pm
@@ -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