po: avoid crash when page is empty
authorJoey Hess <joey@gnu.kitenet.net>
Thu, 21 Jan 2010 20:23:25 +0000 (15:23 -0500)
committerJoey Hess <joey@gnu.kitenet.net>
Thu, 21 Jan 2010 20:33:20 +0000 (15:33 -0500)
Note that there is an associated po4a warning when a page is empty:
  Use of uninitialized value $file in substitution (s///) at /usr/share/perl5/Locale/Po4a/Text.pm line 205.
I've filed a bug with po4a about that, but the important thing is fixing
the crash here.

IkiWiki/Plugin/po.pm
debian/changelog

index 02fc4a89edee391eae291c104d4d3ef113e74e8c..f8801185e2450152f2155fb01ff1da5fdcee607f 100644 (file)
@@ -1057,11 +1057,8 @@ sub commit_and_refresh ($$) {
        IkiWiki::saveindex();
 }
 
-# on success, returns the filtered content.
-# on error, if $nonfatal, warn and return undef; else, error out.
-sub po_to_markup ($$;$) {
+sub po_to_markup ($$) {
        my ($page, $content) = (shift, shift);
-       my $nonfatal = shift;
 
        $content = '' unless defined $content;
        $content = decode_utf8(encode_utf8($content));
@@ -1084,10 +1081,6 @@ sub po_to_markup ($$;$) {
 
        my $fail = sub ($) {
                my $msg = "po(po_to_markup) - $page : " . shift;
-               if ($nonfatal) {
-                       warn $msg;
-                       return undef;
-               }
                error($msg, sub { unlink $infile, $outfile});
        };
 
@@ -1108,8 +1101,7 @@ sub po_to_markup ($$;$) {
        $doc->write($outfile)
                or return $fail->(sprintf(gettext("failed to write %s"), $outfile));
 
-       $content = readfile($outfile)
-               or return $fail->(sprintf(gettext("failed to read %s"), $outfile));
+       $content = readfile($outfile);
 
        # Unlinking should happen automatically, thanks to File::Temp,
        # but it does not work here, probably because of the way writefile()
index 6fbbe0a238a7e209f7e222e72bde95d46f87a972..91f5d78077d8652f3e383e5ecadd66c49a62c6e6 100644 (file)
@@ -13,6 +13,7 @@ ikiwiki (3.20100104) UNRELEASED; urgency=low
   * git: The new git-notes feature in git 1.6.6 changes git log output
     in a way that broke ikiwiki's parser if notes are added to commits.
     Deal with this.
+  * po: Avoid crash when a page is empty.
 
  -- Joey Hess <joeyh@debian.org>  Mon, 04 Jan 2010 12:53:24 -0500