]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
lib: fix update_file timestamps
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 29 Oct 2017 20:00:55 +0000 (13:00 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 29 Oct 2017 20:01:15 +0000 (13:01 -0700)
Problem reported by Bruno Haible in:
https://savannah.gnu.org/support/?109406
* lib/Autom4te/FileUtils.pm (update_file): Use rename + system
instead of move, since move truncates file timestamps.

lib/Autom4te/FileUtils.pm

index 9df2a051d004a08d9aaaf5b194865bcaf4e2dd4f..16b2de97efdbf4a1c23d7b93c5e9fe4f521d3217 100644 (file)
@@ -161,21 +161,20 @@ sub update_file ($$;$)
       return
     }
 
-  if (-f "$to")
+  my $exists = (-f "$to");
+  if ($exists)
     {
-      # Back up and install the new one.
+      # Back up any existing destination.
       move ("$to",  "$to$SIMPLE_BACKUP_SUFFIX")
        or fatal "cannot backup $to: $!";
-      move ("$from", "$to")
-       or fatal "cannot rename $from as $to: $!";
-      msg 'note', "'$to' is updated";
-    }
-  else
-    {
-      move ("$from", "$to")
-       or fatal "cannot rename $from as $to: $!";
-      msg 'note', "'$to' is created";
     }
+
+  # Do not use move ("$from", "$to"), as it truncates file timestamps.
+  rename ("$from", "$to")
+    or system ("mv", "$from", "$to") == 0
+    or fatal "cannot rename $from as $to: $!";
+
+  msg 'note', ($exists ? "'$to' is updated" : "'$to is created")
 }