From 780503433f87c4f8c27d33082efbcb5219543624 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Sun, 22 Mar 2020 16:42:54 -0700 Subject: [PATCH] cleaned up backup-in-place coding to use streamhandle --- lib/Perl/Tidy.pm | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/Perl/Tidy.pm b/lib/Perl/Tidy.pm index 90abd8c5..6523b228 100644 --- a/lib/Perl/Tidy.pm +++ b/lib/Perl/Tidy.pm @@ -1421,15 +1421,13 @@ EOM seek( $output_file, 0, 0 ) or Die("unable to rewind a temporary file for -b option: $!\n"); - # TODO: maybe use streamhandle here - my $fout = IO::File->new("> $input_file") - or Die( + my ( $fout, $iname ) = + Perl::Tidy::streamhandle( $input_file, 'w', $is_encoded_data ); + if ( !$fout ) { + Die( "problem re-opening $input_file for write for -b option; check file and directory permissions: $!\n" - ); - if ($is_encoded_data) { - binmode $fout, ":raw:encoding(UTF-8)"; + ); } - else { binmode $fout } my $line; while ( $line = $output_file->getline() ) { -- 2.39.5