diff options
author | joey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071> | 2007-02-15 02:22:08 +0000 |
---|---|---|
committer | joey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071> | 2007-02-15 02:22:08 +0000 |
commit | d4c61b72813b880d86b316770f2e3819a6428202 (patch) | |
tree | c33e8cae60810b3109400e97dc86fad8baa47027 /IkiWiki/Plugin/search.pm | |
parent | d9592637a962651f06f221839bbc2cfcc6789c83 (diff) | |
download | ikiwiki-d4c61b72813b880d86b316770f2e3819a6428202.tar ikiwiki-d4c61b72813b880d86b316770f2e3819a6428202.tar.gz |
* Many changes to make ikiwiki very resistant to write failures
including out of disk space situations. ikiwiki should never leave
truncated files, and if the error occurs during a web-based file edit,
the user will be given an opportunity to retry.
Inspired by the many ways Moin Moin destroys itself when out of disk. :-)
* Fix syslogging of errors.
Diffstat (limited to 'IkiWiki/Plugin/search.pm')
-rw-r--r-- | IkiWiki/Plugin/search.pm | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/IkiWiki/Plugin/search.pm b/IkiWiki/Plugin/search.pm index 1b5c66716..d35c33e76 100644 --- a/IkiWiki/Plugin/search.pm +++ b/IkiWiki/Plugin/search.pm @@ -89,14 +89,20 @@ sub estcfg () { #{{{ my $estdir="$config{wikistatedir}/hyperestraier"; my $cgi=IkiWiki::basename($config{cgiurl}); $cgi=~s/\..*$//; - open(TEMPLATE, ">:utf8", "$estdir/$cgi.tmpl") || - error("write $estdir/$cgi.tmpl: $!"); + + my $newfile="$estdir/$cgi.tmpl.new"; + my $cleanup = sub { unlink($newfile) }; + open(TEMPLATE, ">:utf8", $newfile) || error("open $newfile: $!", $cleanup); print TEMPLATE IkiWiki::misctemplate("search", "<!--ESTFORM-->\n\n<!--ESTRESULT-->\n\n<!--ESTINFO-->\n\n", - baseurl => IkiWiki::dirname($config{cgiurl})."/"); - close TEMPLATE; - open(TEMPLATE, ">$estdir/$cgi.conf") || - error("write $estdir/$cgi.conf: $!"); + baseurl => IkiWiki::dirname($config{cgiurl})."/") || + error("write $newfile: $!", $cleanup); + close TEMPLATE || error("save $newfile: $!", $cleanup); + rename($newfile, "$estdir/$cgi.tmpl") || + error("rename $newfile: $!", $cleanup); + + $newfile="$estdir/$cgi.conf"; + open(TEMPLATE, ">$newfile") || error("open $newfile: $!", $cleanup); my $template=template("estseek.conf"); eval q{use Cwd 'abs_path'}; $template->param( @@ -105,13 +111,15 @@ sub estcfg () { #{{{ destdir => abs_path($config{destdir}), url => $config{url}, ); - print TEMPLATE $template->output; - close TEMPLATE; + print TEMPLATE $template->output || error("write $newfile: $!", $cleanup); + close TEMPLATE || error("save $newfile: $!", $cleanup); + rename($newfile, "$estdir/$cgi.conf") || + error("rename $newfile: $!", $cleanup); + $cgi="$estdir/".IkiWiki::basename($config{cgiurl}); unlink($cgi); my $estseek = defined $config{estseek} ? $config{estseek} : '/usr/lib/estraier/estseek.cgi'; - symlink($estseek, $cgi) || - error("symlink $estseek $cgi: $!"); + symlink($estseek, $cgi) || error("symlink $estseek $cgi: $!"); } # }}} sub estcmd ($;@) { #{{{ |