--- autoconf-2.67.orig/bin/autom4te.in
+++ autoconf-2.67/bin/autom4te.in
@@ -545,13 +545,21 @@
# stdout is to be handled by hand :(. Don't use fdopen as it means
# we will close STDOUT, which we already do in END.
my $out = new Autom4te::XFile;
- if ($output eq '-')
+ my $atomic_replace;
+ if ($output eq '-' || (-e $output && ! -f $output))
{
$out->open (">$output");
+ $atomic_replace = 0;
}
else
{
- $out->open($output, O_CREAT | O_WRONLY | O_TRUNC, oct ($mode));
+ $out->open("$output.tmp", O_CREAT | O_WRONLY | O_TRUNC, oct ($mode));
+ if ($out) {
+ $atomic_replace = 1;
+ } else {
+ $out->open($output, O_CREAT | O_WRONLY | O_TRUNC, oct ($mode));
+ $atomic_replace = 0;
+ }
}
fatal "cannot create $output: $!"
unless $out;
@@ -590,6 +598,11 @@
$out->close();
+ if ($atomic_replace && !rename("$output.tmp", "$output")) {
+ move ("${output}.tmp", "$output")
+ or fatal "cannot rename ${output}.tmp as $output: $!";
+ }
+
# If no forbidden words, we're done.
return
if ! %prohibited;
@@ -988,7 +1001,8 @@
# If autom4te is younger, then some structures such as C4che might
# have changed, which would corrupt its processing.
Autom4te::C4che->load ($icache_file)
- if -f $icache && mtime ($icache) > mtime ($0);
+ if -f $icache && mtime ($icache) > mtime ($0)
+ && Autom4te::C4che->good_version ($icache_file);
# Add the new trace requests.
my $req = Autom4te::C4che->request ('input' => \@ARGV,