diff options
author | Russ Allbery <rra@cpan.org> | 2021-12-26 11:44:18 -0800 |
---|---|---|
committer | Russ Allbery <rra@cpan.org> | 2021-12-26 11:44:18 -0800 |
commit | ce27d84e1099ab334d0a1ab3bbd4501807da69d2 (patch) | |
tree | 8fbcbe5dae640effb820caacc07aa213c218c7b9 | |
parent | 75c718ef14e3b688e834984b146fd4f21c6c97a9 (diff) |
Don't overwrite files if generation fails
App::DocKnot::Generate was overwriting the output file before it
attempted to generate the new version, resulting in zeroing the
file if generation failed with an error. Wait to open the output
file for writing until after the new output has been generated
without errors.
-rw-r--r-- | Changes | 3 | ||||
-rw-r--r-- | lib/App/DocKnot/Generate.pm | 5 |
2 files changed, 6 insertions, 2 deletions
@@ -5,6 +5,9 @@ - Fix spurious requirement for a package metadata file when running docknot spin. + - Don't overwrite output files from docknot generate or generate-all + if the generation fails. + 6.00 - 2021-12-25 - Add a new *.spin input file for docknot spin that points to an external diff --git a/lib/App/DocKnot/Generate.pm b/lib/App/DocKnot/Generate.pm index 8caa7a8..f94b718 100644 --- a/lib/App/DocKnot/Generate.pm +++ b/lib/App/DocKnot/Generate.pm @@ -18,6 +18,7 @@ use parent qw(App::DocKnot); use warnings; use App::DocKnot::Config; +use App::DocKnot::Util qw(print_fh); use Carp qw(croak); use Encode qw(encode); use Template; @@ -525,9 +526,9 @@ sub generate_output { } # Generate the output. + my $data = $self->generate($template); open(my $outfh, '>', $output); - print {$outfh} encode('utf-8', $self->generate($template)) - or croak("cannot write to $output: $!"); + print_fh($outfh, $output, encode('utf-8', $data)); close($outfh); return; } |