Bug 20370 – On POSIX, std.file.copy only copies the file times at second precision

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
All
Creation time
2019-11-08T14:27:05Z
Last change time
2020-09-18T12:59:22Z
Keywords
pull
Assigned to
No Owner
Creator
Jonathan M Davis

Comments

Comment #0 by issues.dlang — 2019-11-08T14:27:05Z
Currently, on POSIX systems, after std.file.copy has copied the file, it sets the access time and modification times of the copy to be the same as the original using utime: utimbuf utim = void; utim.actime = cast(time_t) statbufr.st_atime; utim.modtime = cast(time_t) statbufr.st_mtime; cenforce(utime(toz, &utim) != -1, f, fromz); utime only has second precision (as shown by the cast to time_t). The result is that if you copy a file on a file system that supports sub-second precision (which should be most file systems), the copy will actually be considered newer than the original. E.G. if the modification time of the original was "2019-Nov-07 19:41:49.2518144", the copy would be "2019-Nov-07 19:41:49". So, std.file.copy should changed to use a function with sub-second precision. From the little bit of research I've done thus far, it looks like utimensat would be the correct replacement (it having nanosecond precision and being from "IEEE Std 1003.1-2008 ('POSIX.1')"). It looks like FreeBSD and Linux both have this function, and druntime has it for both. I don't know if Mac OS X has it or not, but druntime does not have it for Darwin. Assuming that it's not just missing from druntime, we could use utimes on Mac OS X, which isn't as good as utimensat (utimes only has microsecond precision), but it's still better than utime.
Comment #1 by dlang-bot — 2020-09-12T03:44:56Z
@n8sh created dlang/phobos pull request #7629 "On POSIX std.file.copy was copying file times at second precision" fixing this issue: - Fix Issue 20370 - On POSIX, std.file.copy only copies the file times at second precision https://github.com/dlang/phobos/pull/7629
Comment #2 by dlang-bot — 2020-09-16T07:31:51Z
dlang/phobos pull request #7629 "On POSIX std.file.copy was copying file times at second precision" was merged into stable: - 99e7366b99c240014eaabd0ec496584efe2c0bde by Nathan Sashihara: Fix Issue 20370 - On POSIX, std.file.copy only copies the file times at second precision https://github.com/dlang/phobos/pull/7629
Comment #3 by dlang-bot — 2020-09-18T12:59:22Z
dlang/phobos pull request #7639 "merge stable" was merged into master: - b8e9e70e9046aafe723e2184fcdf2c6f069bc9f6 by Nathan Sashihara: Fix Issue 20370 - On POSIX, std.file.copy only copies the file times at second precision https://github.com/dlang/phobos/pull/7639