X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/1379fa74021647d12730e19547d339aedd48d833..fa52a730ff3b30c7d2cdd8cd5f9c8c25a0c0a2a5:/IkiWiki/Plugin/aggregate.pm 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 () { #{{{