From a58d1187535d04e1757083ed1529d7f4c1e38ac8 Mon Sep 17 00:00:00 2001 From: Wayne Davison Date: Tue, 4 Dec 2007 01:40:18 +0000 Subject: [PATCH] 24147 --- ChangeLog | 4 ++++ Util/difflog.pl | 19 +++++++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 03a52f752..7d8dba60f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,10 @@ * 24148: configure.ac, Src/utils.c: attempt to use strerror_r() to make error messages in signal handle safer. +2007-12-03 Wayne Davison + + * 24147: Util/difflog.pl: improved the temporary-file handling. + 2007-12-03 Peter Stephenson * 24143: Etc/zsh-development-guide, Util/.distfiles: Remove diff --git a/Util/difflog.pl b/Util/difflog.pl index 9872ded69..ff2d4bc16 100644 --- a/Util/difflog.pl +++ b/Util/difflog.pl @@ -2,10 +2,9 @@ use strict; use IO::File; +use File::Temp qw(tempfile); my @differ = qw(diff -bw); -my $oldtmp = "/tmp/difflog$$.old"; -my $newtmp = "/tmp/difflog$$.new"; my $newfn = pop(@ARGV); my $oldfn = pop(@ARGV); @@ -36,16 +35,16 @@ while ($old < @oldentries && $new < @newentries) else { if ($oldhash{$oldentries[$old]} ne $newhash{$newentries[$new]}) { - my $oldfh = new IO::File("/tmp/difflog$$.old", 'w'); - $oldfh->print($oldhash{$oldentries[$old]}); - $oldfh->close(); - my $newfh = new IO::File("/tmp/difflog$$.new", 'w'); - $newfh->print($newhash{$newentries[$new]}); - $newfh->close(); - open(DIFF, join(' ', @differ, @ARGV, $oldtmp, $newtmp, '|')); + my($oldfh, $oldtmp) = tempfile('difflog-XXXXXXXX', SUFFIX => '.old', DIR => '/tmp'); + print $oldfh $oldhash{$oldentries[$old]}; + close($oldfh); + my($newfh, $newtmp) = tempfile('difflog-XXXXXXXX', SUFFIX => '.new', DIR => '/tmp'); + print $newfh $newhash{$newentries[$new]}; + close($newfh); + open(DIFF, '-|', @differ, @ARGV, $oldtmp, $newtmp) or die $!; my @lines = ; close(DIFF); - unlink ; + unlink($oldtmp, $newtmp); if (@lines) { print "diff for ", $oldentries[$old], ":\n";