]> git.ipfire.org Git - thirdparty/automake.git/commitdiff
Use higher-resolution file timestamps
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 2 Feb 2023 22:17:52 +0000 (14:17 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 2 Feb 2023 22:20:09 +0000 (14:20 -0800)
* lib/Automake/FileUtils.pm (mtime):
Return higher-resolution file timestamps.
This isn’t perfect, but it’s better than what we had.
Code change taken from Autoconf to partially fix a race
<https://bugs.gentoo.org/show_bug.cgi?id=782985>.

lib/Automake/FileUtils.pm

index bd173032be2eb0e3b5536080625d9187f7a69068..6e9796a98011e2720a99e1ef8046ac14c07be547 100644 (file)
@@ -39,7 +39,7 @@ use strict;
 use warnings FATAL => 'all';
 
 use Exporter;
-use File::stat;
+use Time::HiRes qw(stat);
 use IO::File;
 
 use Automake::Channels;
@@ -115,10 +115,16 @@ sub mtime ($)
   return 0
     if $file eq '-' || ! -f $file;
 
-  my $stat = stat ($file)
+  my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
+    $atime,$mtime,$ctime,$blksize,$blocks) = stat ($file)
     or fatal "cannot stat $file: $!";
 
-  return $stat->mtime;
+  # Unfortunately Time::HiRes converts timestamps to floating-point, and the
+  # rounding error can be hundreds of nanoseconds for circa-2023 timestamps.
+  # Perhaps some day Perl will support accurate file timestamps.
+  # For now, do the best we can without going outside Perl.
+
+  return $mtime;
 }