github.com/containerd/Containerd@v1.4.13/archive/time.go (about) 1 /* 2 Copyright The containerd Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package archive 18 19 import ( 20 "syscall" 21 "time" 22 "unsafe" 23 ) 24 25 var ( 26 minTime = time.Unix(0, 0) 27 maxTime time.Time 28 ) 29 30 func init() { 31 if unsafe.Sizeof(syscall.Timespec{}.Nsec) == 8 { 32 // This is a 64 bit timespec 33 // os.Chtimes limits time to the following 34 maxTime = time.Unix(0, 1<<63-1) 35 } else { 36 // This is a 32 bit timespec 37 maxTime = time.Unix(1<<31-1, 0) 38 } 39 } 40 41 func boundTime(t time.Time) time.Time { 42 if t.Before(minTime) || t.After(maxTime) { 43 return minTime 44 } 45 46 return t 47 } 48 49 func latestTime(t1, t2 time.Time) time.Time { 50 if t1.Before(t2) { 51 return t2 52 } 53 return t1 54 }