From: Nicholas Clark Date: Sun, 23 Jan 2011 09:39:21 +0000 (+0000) Subject: In regen_lib.pl, when opening, first unlink a previous file of that name. X-Git-Tag: accepted/trunk/20130322.191538~5853 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=396ce246b9969d83ec11500def9604b58fb4c726;p=platform%2Fupstream%2Fperl.git In regen_lib.pl, when opening, first unlink a previous file of that name. Previously regcomp.pl had an explicit unlink for the file it creates, but none of the other regen/*.pl scripts did. Also, remove commented out code relating to unlink. --- diff --git a/regen/reentr.pl b/regen/reentr.pl index 3586bc1..963dd96 100644 --- a/regen/reentr.pl +++ b/regen/reentr.pl @@ -51,7 +51,6 @@ my %map = ( # Example #3: S_CBI means type func_r(const char*, char*, int) -# safer_unlink 'reentr.h'; my $h = safer_open("reentr.h-new"); select $h; print read_only_top(lang => 'C', by => 'regen/reentr.pl', @@ -792,7 +791,6 @@ rename_if_different('reentr.h-new', 'reentr.h'); # Prepare to write the reentr.c. -# safer_unlink 'reentr.c'; my $c = safer_open("reentr.c-new"); select $c; my $top = read_only_top(lang => 'C', by => 'regen/reentr.pl', diff --git a/regen/regcomp.pl b/regen/regcomp.pl index 913dda5..98a3889 100644 --- a/regen/regcomp.pl +++ b/regen/regcomp.pl @@ -17,7 +17,6 @@ BEGIN { # Get function prototypes require 'regen/regen_lib.pl'; } -#use Fatal qw(open close rename chmod unlink); use strict; open DESC, 'regcomp.sym'; @@ -129,8 +128,6 @@ EOP my $tmp_h = 'regnodes.h-new'; -unlink $tmp_h if -f $tmp_h; - my $out = safer_open($tmp_h); print $out read_only_top(lang => 'C', by => 'regen/regcomp.pl', diff --git a/regen/regen_lib.pl b/regen/regen_lib.pl index b4d9f86..880a975 100644 --- a/regen/regen_lib.pl +++ b/regen/regen_lib.pl @@ -63,6 +63,9 @@ sub rename_if_different { # Saf*er*, but not totally safe. And assumes always open for output. sub safer_open { my $name = shift; + if (-f $name) { + unlink $name or die "$name exists but can't unlink: $!"; + } my $fh = gensym; open $fh, ">$name" or die "Can't create $name: $!"; *{$fh}->{name} = $name;