[Issue 20785] New: std.file.setTimes: on macOS use setattrlist to avoid truncating timestamp precision to microseconds

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Apr 29 04:31:15 UTC 2020


https://issues.dlang.org/show_bug.cgi?id=20785

          Issue ID: 20785
           Summary: std.file.setTimes: on macOS use setattrlist to avoid
                    truncating timestamp precision to microseconds
           Product: D
           Version: D2
          Hardware: All
                OS: Mac OS X
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody at puremagic.com
          Reporter: n8sh.secondary at hotmail.com

This was brought to my attention by a unit test in
https://github.com/CyberShadow/ae/blob/master/sys/persistence/core.d that was
failing on macOS because it was storing a result of `timeLastModified` then
using the stored value as an argument to `setTimes` and expecting that the next
call to `timeLastModified` would yield the same result as the stored value. The
problem is that on macOS std.file uses hecto-nanosecond precision (converted
from nanosecond) when reading file access/modification times but only uses
microsecond precision when writing them. This is because
core.sys.posix.sys.stat does not have `utimensat` for macOS, which is because
it only became available in macOS starting from version 10.13 which was
released in 2017. As an alternative `setattrlist` can be used with any version
of macOS to set timestamps with the same precision as `utimensat`.

--


More information about the Digitalmars-d-bugs mailing list