_teefile_stream_ => $i++,
_user_formatter_ => $i++,
_input_copied_verbatim_ => $i++,
+ _input_output_difference_ => $i++,
};
}
$self->set_output_file_permissions( $backup_file, \@input_file_stat,
$in_place_modify );
+ # set the modification time of the copy to the original value (rt#145999)
+ my ( $read_time, $write_time ) = @input_file_stat[ 8, 9 ];
+ if ( defined($write_time) ) {
+ utime( $read_time, $write_time, $backup_file )
+ || Warn("error setting times for backup file '$backup_file'\n");
+ }
+
# Open the original input file for writing ... opening with ">" will
# truncate the existing data.
open( my $fout, ">", $input_file )
$self->set_output_file_permissions( $input_file, \@input_file_stat,
$in_place_modify );
+ # Keep original modification time if no change (rt#145999)
+ if ( !$self->[_input_output_difference_] && defined($write_time) ) {
+ utime( $read_time, $write_time, $input_file )
+ || Warn("error setting times for '$input_file'\n");
+ }
+
#---------------------------------------------------------
# remove the original file for in-place modify as follows:
# $delete_backup=0 never
$self->set_output_file_permissions( $input_file, \@input_file_stat,
$in_place_modify );
+ # Keep original modification time if no change (rt#145999)
+ my ( $read_time, $write_time ) = @input_file_stat[ 8, 9 ];
+ if ( !$self->[_input_output_difference_] && defined($write_time) ) {
+ utime( $read_time, $write_time, $input_file )
+ || Warn("error setting times for '$input_file'\n");
+ }
+
#---------------------------------------------------------
# remove the original file for in-place modify as follows:
# $delete_backup=0 never
$self->[_output_file_] = $output_file;
$self->[_teefile_stream_] = $teefile_stream;
$self->[_input_copied_verbatim_] = 0;
+ $self->[_input_output_difference_] = 1; ## updated later if -b used
#----------------------------------------------------------
# Do all formatting of this buffer.
my $sink_object;
# vars for checking assertions, if needed
- my $digest_input = 0;
+ my $digest_input;
my $saved_input_buf;
my $ref_destination_stream = ref($destination_stream);
# if needed. These are only used for 'tidy' formatting.
if ( $rOpts->{'format'} eq 'tidy' ) {
- # evaluate MD5 sum of input file for assert tests before any prefilter
- if ( $rOpts->{'assert-tidy'} || $rOpts->{'assert-untidy'} ) {
+ # evaluate MD5 sum of input file, if needed, before any prefilter
+ if ( $rOpts->{'assert-tidy'}
+ || $rOpts->{'assert-untidy'}
+ || $rOpts->{'backup-and-modify-in-place'} )
+ {
$digest_input = $md5_hex->($buf);
$saved_input_buf = $buf;
}
$postfilter
|| $remove_terminal_newline
|| $rOpts->{'assert-tidy'}
- || $rOpts->{'assert-untidy'};
+ || $rOpts->{'assert-untidy'}
+ || $rOpts->{'backup-and-modify-in-place'};
#-------------------------
# Setup destination_buffer
? $postfilter->($postfilter_buffer)
: $postfilter_buffer;
+ if ( defined($digest_input) ) {
+ my $digest_output = $md5_hex->($buf_post);
+ $self->[_input_output_difference_] =
+ $digest_output ne $digest_input;
+ }
+
# Check if file changed if requested, but only after any postfilter
if ( $rOpts->{'assert-tidy'} ) {
- my $digest_output = $md5_hex->($buf_post);
- if ( $digest_output ne $digest_input ) {
+ if ( $self->[_input_output_difference_] ) {
my $diff_msg =
compare_string_buffers( $saved_input_buf, $buf_post,
$is_encoded_data );
}
if ( $rOpts->{'assert-untidy'} ) {
- my $digest_output = $md5_hex->($buf_post);
- if ( $digest_output eq $digest_input ) {
+ if ( !$self->[_input_output_difference_] ) {
$logger_object->warning(
"assertion failure: '--assert-untidy' is set but output equals input\n"
);