summaryrefslogtreecommitdiff
path: root/ikiwiki
diff options
context:
space:
mode:
authorjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>2006-03-16 21:06:33 +0000
committerjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>2006-03-16 21:06:33 +0000
commitd623952512f406a6c9a3c8e40437070a68f96193 (patch)
tree97ab633fc0f0c374d14b2e5eb3d94bb960d5348d /ikiwiki
parent18879c0a1481150a3a333415ae4186d46dcdcb08 (diff)
lock wiki and refuse to traverse symlinks
Diffstat (limited to 'ikiwiki')
-rwxr-xr-xikiwiki22
1 files changed, 21 insertions, 1 deletions
diff --git a/ikiwiki b/ikiwiki
index 1361b5b67..cb90ef04f 100755
--- a/ikiwiki
+++ b/ikiwiki
@@ -401,6 +401,25 @@ sub render ($) { #{{{
}
} #}}}
+sub lockwiki () { #{{{
+ # Take an exclusive lock on the wiki to prevent multiple concurrent
+ # run issues. The lock will be dropped on program exit.
+ if (! -d "$config{srcdir}/.ikiwiki") {
+ mkdir("$config{srcdir}/.ikiwiki");
+ }
+ open(WIKILOCK, ">$config{srcdir}/.ikiwiki/lockfile") || error ("cannot write to lockfile: $!");
+ if (! flock(WIKILOCK, 2 | 4)) {
+ debug("wiki seems to be locked, waiting for lock");
+ my $wait=600; # arbitrary, but don't hang forever to
+ # prevent process pileup
+ for (1..600) {
+ return if flock(WIKILOCK, 2 | 4);
+ sleep 1;
+ }
+ error("wiki is locked; waited $wait seconds without lock being freed (possible stuck process or stale lock?)");
+ }
+} #}}}
+
sub loadindex () { #{{{
open (IN, "$config{srcdir}/.ikiwiki/index") || return;
while (<IN>) {
@@ -557,7 +576,7 @@ sub refresh () { #{{{
$File::Find::prune=1;
use warnings "all";
}
- elsif (! -d $_) {
+ elsif (! -d $_ && ! -l $_) {
my ($f)=/$config{wiki_file_regexp}/; # untaint
if (! defined $f) {
warn("skipping bad filename $_\n");
@@ -1172,6 +1191,7 @@ sub setup () { # {{{
} #}}}
# main {{{
+lockwiki();
setup() if $config{setup};
if ($config{wrapper}) {
gen_wrapper(%config);