summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZack Weinberg <zackw@panix.com>2020-11-30 11:26:06 -0500
committerZack Weinberg <zackw@panix.com>2020-11-30 11:45:26 -0500
commit623ec9a0d1800f827f5167f2075bf7dc2342463c (patch)
treee775427ff111bcf5f7261f44ecf9273faefb571a
parent9886b7a922fd90cc86b19106293250da652256aa (diff)
downloadautoconf-623ec9a0d1800f827f5167f2075bf7dc2342463c.tar.gz
Avoid ‘new File::Temp’ in Perl scripts.
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.
-rw-r--r--bin/autom4te.in18
-rw-r--r--bin/autoreconf.in7
2 files changed, 9 insertions, 16 deletions
diff --git a/bin/autom4te.in b/bin/autom4te.in
index 9aa0d1f1..e54fa145 100644
--- a/bin/autom4te.in
+++ b/bin/autom4te.in
@@ -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
diff --git a/bin/autoreconf.in b/bin/autoreconf.in
index ec0a12e2..e564d18c 100644
--- a/bin/autoreconf.in
+++ b/bin/autoreconf.in
@@ -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;