Since it seems that lastAccessed and lastModified have a resolution of 1s, I could understand if the modification time in the above case were rounded down to 17:02:28 or rounded up to 17:02:29, but the reported time of 17:02:27 seems baffling. (Did some optimization reorder statements?)
One interesting thing that I've observed is that all of the failures I've seen occur when the fractional seconds are <5ms.
I thought that it might be a bug in the underlying filesystem, but I have been unsuccessful reproducing this bug with analogous C code:
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <sys/stat.h>
#include <unistd.h>
static void printError(const char* message, int err) {
fprintf(stderr, "%s: %s (%d)\n", message, strerror(err), err);
}
int main(void) {
// Run for up to 10 seconds.
time_t stopTime = time(NULL) + 10;
time_t now;
const char* filePath = "/tmp/file-time-test";
do {
FILE* fp;
struct stat statBuf = { 0 };
now = time(NULL);
fp = fopen(filePath, "wb");
if (fp == NULL) {
printError("fopen failed", errno);
break;
}
fclose(fp);
if (stat(filePath, &statBuf) != 0) {
printError("stat failed", errno);
break;
}
if (now > statBuf.st_mtime) {
printf("Unexpected mtime:\n"
"now: %lld\n"
"mtime: %lld\n",
(long long) now,
(long long) statBuf.st_mtime);
break;
}
} while (now < stopTime);
return 0;
}
(I tested with Dart SDK 2.8.4 on a 64-bit Linux system.)
package:file
has tests to verify thatlastAccessed
andlastModified
timestamps are within an expected range, and those tests have been flaky for local filesystems.Reproduction code that creates a new
File
and sanity-checks itslastModified
time, repeating as many times as it can for 1 second:Output from an example failure:
Since it seems that
lastAccessed
andlastModified
have a resolution of 1s, I could understand if the modification time in the above case were rounded down to 17:02:28 or rounded up to 17:02:29, but the reported time of 17:02:27 seems baffling. (Did some optimization reorder statements?)One interesting thing that I've observed is that all of the failures I've seen occur when the fractional seconds are <5ms.
I thought that it might be a bug in the underlying filesystem, but I have been unsuccessful reproducing this bug with analogous C code:
(I tested with Dart SDK 2.8.4 on a 64-bit Linux system.)