1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
Description: Make autom4te atomically replace its output file.
Upstream is not interested in this patch; see Forwarded: URL.
Forwarded: http://lists.gnu.org/archive/html/autoconf-patches/2008-08/msg00032.html
Bug-Debian: http://bugs.debian.org/221483
Author: Ben Pfaff <pfaffben@debian.org>
Last-Update: 2006-05-25
--- autoconf-2.68.orig/bin/autom4te.in
+++ autoconf-2.68/bin/autom4te.in
@@ -544,13 +544,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;
@@ -589,6 +597,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;
|