From 2c9684e35c25c4d54d9904999990b67e24ac1da5 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 26 Jan 2022 15:36:49 +0100 Subject: [PATCH] pkg/system: add note about maxTime This code caused me some head-scratches, and initially I wondered if this was a bug, but it looks to be intentional to set nsec, not sec, as time.Unix() internally divides nsec, and sets sec accordingly; https://github.com/golang/go/blob/go1.19.2/src/time/time.go#L1364-L1380 // Unix returns the local Time corresponding to the given Unix time, // sec seconds and nsec nanoseconds since January 1, 1970 UTC. // It is valid to pass nsec outside the range [0, 999999999]. // Not all sec values have a corresponding time value. One such // value is 1<<63-1 (the largest int64 value). func Unix(sec int64, nsec int64) Time { if nsec < 0 || nsec >= 1e9 { n := nsec / 1e9 sec += n nsec -= n * 1e9 if nsec < 0 { nsec += 1e9 sec-- } } return unixTime(sec, int32(nsec)) } Signed-off-by: Sebastiaan van Stijn --- pkg/system/chtimes.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/system/chtimes.go b/pkg/system/chtimes.go index 7cd751f089..537ddadc63 100644 --- a/pkg/system/chtimes.go +++ b/pkg/system/chtimes.go @@ -14,6 +14,10 @@ func init() { if unsafe.Sizeof(syscall.Timespec{}.Nsec) == 8 { // This is a 64 bit timespec // os.Chtimes limits time to the following + // + // Note that this intentionally sets nsec (not sec), which sets both sec + // and nsec internally in time.Unix(); + // https://github.com/golang/go/blob/go1.19.2/src/time/time.go#L1364-L1380 maxTime = time.Unix(0, 1<<63-1) } else { // This is a 32 bit timespec