[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[automake-commit] 02/02: Use higher-resolution file timestamps
From: |
Paul Eggert |
Subject: |
[automake-commit] 02/02: Use higher-resolution file timestamps |
Date: |
Thu, 02 Feb 2023 17:20:19 -0500 |
eggert pushed a commit to branch master
in repository automake.
View the commit online:
https://git.savannah.gnu.org/gitweb/?p=automake.git;a=commitdiff;h=01bf65daf6f6627b56fbe78fc436fd877ccd3537
commit 01bf65daf6f6627b56fbe78fc436fd877ccd3537
Author: Paul Eggert <eggert@cs.ucla.edu>
AuthorDate: Thu Feb 2 14:17:52 2023 -0800
Use higher-resolution file timestamps
* 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 | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/lib/Automake/FileUtils.pm b/lib/Automake/FileUtils.pm
index bd173032b..6e9796a98 100644
--- a/lib/Automake/FileUtils.pm
+++ b/lib/Automake/FileUtils.pm
@@ -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;
}