summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/aggregate.pm
diff options
context:
space:
mode:
authorjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>2007-02-15 02:22:08 +0000
committerjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>2007-02-15 02:22:08 +0000
commitd4c61b72813b880d86b316770f2e3819a6428202 (patch)
treec33e8cae60810b3109400e97dc86fad8baa47027 /IkiWiki/Plugin/aggregate.pm
parentd9592637a962651f06f221839bbc2cfcc6789c83 (diff)
* 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/aggregate.pm')
-rw-r--r--IkiWiki/Plugin/aggregate.pm13
1 files changed, 9 insertions, 4 deletions
diff --git a/IkiWiki/Plugin/aggregate.pm b/IkiWiki/Plugin/aggregate.pm
index 7fceb0df3..a6f850236 100644
--- a/IkiWiki/Plugin/aggregate.pm
+++ b/IkiWiki/Plugin/aggregate.pm
@@ -153,8 +153,11 @@ sub loadstate () { #{{{
sub savestate () { #{{{
eval q{use HTML::Entities};
error($@) if $@;
- open (OUT, ">$config{wikistatedir}/aggregate" ||
- die "$config{wikistatedir}/aggregate: $!");
+ my $newfile="$config{wikistatedir}/aggregate.new";
+ # TODO: This cleanup function could use improvement. Any newly
+ # aggregated files are left behind unrecorded, and should be deleted.
+ my $cleanup = sub { unlink($newfile) };
+ open (OUT, ">$newfile") || error("open $newfile: $!", $cleanup);
foreach my $data (values %feeds, values %guids) {
if ($data->{remove}) {
if ($data->{name}) {
@@ -188,9 +191,11 @@ sub savestate () { #{{{
push @line, "$field=".$data->{$field};
}
}
- print OUT join(" ", @line)."\n";
+ print OUT join(" ", @line)."\n" || error("write $newfile: $!", $cleanup);
}
- close OUT;
+ close OUT || error("save $newfile: $!", $cleanup);
+ rename($newfile, "$config{wikistatedir}/aggregate") ||
+ error("rename $newfile: $!", $cleanup);
} #}}}
sub expire () { #{{{