Skip to content

Commit 1a3bf7a

Browse files
author
H. Peter Anvin (Intel)
committed
warnings.pl: again, don't update the timestamp unless we need to
Don't update the timestamp unless we really have to do so. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
1 parent eeccbfe commit 1a3bf7a

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

asm/warnings.pl

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -279,17 +279,20 @@ sub sort_warnings {
279279
close($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;
295298
close($out);

0 commit comments

Comments
 (0)