From: Paul Eggert Date: Sun, 29 Oct 2017 20:00:55 +0000 (-0700) Subject: lib: fix update_file timestamps X-Git-Tag: v2.69b~42 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e5f5e535adec83b146bfc921d9005ecf6a846464;p=thirdparty%2Fautoconf.git lib: fix update_file timestamps 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. --- diff --git a/lib/Autom4te/FileUtils.pm b/lib/Autom4te/FileUtils.pm index 9df2a051..16b2de97 100644 --- a/lib/Autom4te/FileUtils.pm +++ b/lib/Autom4te/FileUtils.pm @@ -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") }