# 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 '-')
{
{
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, "<");
}
$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
# 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;
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;