@@ -279,17 +279,20 @@ sub sort_warnings {
279279close ($out );
280280
281281# Write data to file if and only if it has changed
282- # Windows requires append mode here
283- open ($out , ' +>>' , $outfile )
284- or die " $0 : cannot open output file $outfile : $! \n " ;
285- my $datalen = length ($outdata );
286- my $oldlen = read ($out , my $oldoutdata , $datalen +1);
287- if (!defined ($oldlen ) || $oldlen != $datalen ||
288- !($oldoutdata eq $outdata )) {
289- # Data changed, must rewrite
290- truncate ($out , 0);
291- seek ($out , 0, SEEK_SET)
292- or die " $0 : cannot rewind output file $outfile : $! \n " ;
293- print $out $outdata ;
282+ # For some systems, even if we don't write, opening for append
283+ # apparently touches the timestamp, so we need to read and write
284+ # as separate operations.
285+ if (open (my $out , ' <' , $outfile )) {
286+ my $datalen = length ($outdata );
287+ my $oldlen = read ($out , my $oldoutdata , $datalen +1);
288+ close ($out );
289+ exit 0 if (defined ($oldlen ) && $oldlen == $datalen &&
290+ ($oldoutdata eq $outdata ));
294291}
292+
293+ # Data changed, must rewrite
294+ open (my $out , ' >' , $outfile )
295+ or die " $0 : cannot open output file $outfile : $! \n " ;
296+
297+ print $out $outdata ;
295298close ($out );
0 commit comments