]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
Avoid ‘new File::Temp’ in Perl scripts.
authorZack Weinberg <zackw@panix.com>
Mon, 30 Nov 2020 16:26:06 +0000 (11:26 -0500)
committerZack Weinberg <zackw@panix.com>
Mon, 30 Nov 2020 16:45:26 +0000 (11:45 -0500)
Despite what the documentation says, ‘new File::Temp’ does not work
reliably in perl 5.6.x.  Rather than figure out exactly what is wrong
with it, let’s just stick to ‘tempfile’.

 * bin/autom4te.in (handle_output): Use tempfile function instead of
   object-oriented File::Temp interface.
 * bin/autoreconf.in (install_aux_file): Likewise.

bin/autom4te.in
bin/autoreconf.in

index 9aa0d1f1b50d4f3af9bb045482f69e01e0740ad5..e54fa145aaeb7578d2782cd775765680936511e2 100644 (file)
@@ -548,7 +548,7 @@ sub handle_output ($$)
 
   # Read the (cached) raw M4 output, produce the actual result.
   # If we are writing to a regular file, replace it atomically.
-  my $atomic_replace = 0;
+  my $scratchfile;
   my $out;
   if ($output eq '-')
     {
@@ -564,18 +564,14 @@ sub handle_output ($$)
     {
       my (undef, $outdir, undef) = fileparse ($output);
 
-      use File::Temp ();
-      $out = new File::Temp (UNLINK => 0, DIR => $outdir);
+      use File::Temp qw (tempfile);
+      ($out, $scratchfile) = tempfile (UNLINK => 0, DIR => $outdir);
       fatal "cannot create a file in $outdir: $!"
         unless $out;
 
       # File::Temp doesn't give us access to 3-arg open(2), unfortunately.
-      # In older Perls, implicit conversion of a File::Temp to its filename
-      # cannot be relied upon.
-      chmod (oct ($mode) & ~(umask), $out->filename)
-        or fatal "setting mode of " . $out->filename . ": $!";
-
-      $atomic_replace = 1;
+      chmod (oct ($mode) & ~(umask), $scratchfile)
+        or fatal "setting mode of " . $scratchfile . ": $!";
     }
 
   my $in = new Autom4te::XFile ($ocache . $req->id, "<");
@@ -613,8 +609,8 @@ sub handle_output ($$)
     }
 
   $out->close();
-  update_file ($out->filename, $output, $force)
-    if $atomic_replace;
+  update_file ($scratchfile, $output, $force)
+    if defined $scratchfile;
 
   # If no forbidden words, we're done.
   return
index ec0a12e2b9f417d673c6389ca56aaea792449c3e..e564d18c75175d3ae4d28a70b0eb521576ae8412 100644 (file)
@@ -46,7 +46,7 @@ BEGIN
 # Do not use Cwd::chdir, since it might hang.
 use Cwd qw (cwd);
 use File::Copy qw (copy);
-use File::Temp ();
+use File::Temp qw (tempfile);
 
 use Autom4te::ChannelDefs;
 use Autom4te::Channels;
@@ -362,10 +362,7 @@ sub install_aux_file
           unlink $dest
             or fatal "rm -f $dest: $!\n";
         }
-      my $temp = new File::Temp (UNLINK => 0, DIR => $destdir);
-      # Older Perls don't convert $temp to its filename
-      # in all the places we need it to.
-      my $tempname = $temp->filename;
+      my ($temp, $tempname) = tempfile (UNLINK => 0, DIR => $destdir);
       copy ($src, $tempname)
         or fatal "copying $src to $tempname: $!\n";
       make_executable ($tempname) if -x $src;