summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2017-10-29 13:00:55 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2017-10-29 13:01:15 -0700
commite5f5e535adec83b146bfc921d9005ecf6a846464 (patch)
tree9fc36a8a9bbed00b482c882c676f65bf03c70fe5 /lib
parentb0ee838e1193899d28f0bfb51192a02d48e4b472 (diff)
downloadautoconf-e5f5e535adec83b146bfc921d9005ecf6a846464.tar.gz
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.
Diffstat (limited to 'lib')
-rw-r--r--lib/Autom4te/FileUtils.pm21
1 files changed, 10 insertions, 11 deletions
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")
}