diff options
| author | Sebastian Thiel <sebastian.thiel@icloud.com> | 2023-10-31 15:05:06 +0100 |
|---|---|---|
| committer | Sebastian Thiel <sebastian.thiel@icloud.com> | 2023-10-31 17:00:59 +0100 |
| commit | a8ece1190bf6b340175bc5b688e52bd29924f483 (patch) | |
| tree | df798ec1ab8e9a17d0f7af9fbbad65a2e04f4322 /tests/rustdoc-js-std/parser-paths.js | |
| parent | 650991d62c3a2c80ba27009d06839adbb038bf5e (diff) | |
| download | rust-a8ece1190bf6b340175bc5b688e52bd29924f483.tar.gz rust-a8ece1190bf6b340175bc5b688e52bd29924f483.zip | |
Add support for pre-unix-epoch file dates on Apple platforms (#108277)
Time in UNIX system calls counts from the epoch, 1970-01-01. The timespec struct used in various system calls represents this as a number of seconds and a number of nanoseconds. Nanoseconds are required to be between 0 and 999_999_999, because the portion outside that range should be represented in the seconds field; if nanoseconds were larger than 999_999_999, the seconds field should go up instead. Suppose you ask for the time 1969-12-31, what time is that? On UNIX systems that support times before the epoch, that's seconds=-86400, one day before the epoch. But now, suppose you ask for the time 1969-12-31 23:59:00.1. In other words, a tenth of a second after one minute before the epoch. On most UNIX systems, that's represented as seconds=-60, nanoseconds=100_000_000. The macOS bug is that it returns seconds=-59, nanoseconds=-900_000_000. While that's in some sense an accurate description of the time (59.9 seconds before the epoch), that violates the invariant of the timespec data structure: nanoseconds must be between 0 and 999999999. This causes this assertion in the Rust standard library. So, on macOS, if we get a Timespec value with seconds less than or equal to zero, and nanoseconds between -999_999_999 and -1 (inclusive), we can add 1_000_000_000 to the nanoseconds and subtract 1 from the seconds, and then convert. The resulting timespec value is still accepted by macOS, and when fed back into the OS, produces the same results. (If you set a file's mtime with that timestamp, then read it back, you get back the one with negative nanoseconds again.) Co-authored-by: Josh Triplett <josh@joshtriplett.org>
Diffstat (limited to 'tests/rustdoc-js-std/parser-paths.js')
0 files changed, 0 insertions, 0 deletions
