github.com/ssdev-go/moby@v17.12.1-ce-rc2+incompatible/pkg/system/chtimes.go (about) 1 package system 2 3 import ( 4 "os" 5 "time" 6 ) 7 8 // Chtimes changes the access time and modified time of a file at the given path 9 func Chtimes(name string, atime time.Time, mtime time.Time) error { 10 unixMinTime := time.Unix(0, 0) 11 unixMaxTime := maxTime 12 13 // If the modified time is prior to the Unix Epoch, or after the 14 // end of Unix Time, os.Chtimes has undefined behavior 15 // default to Unix Epoch in this case, just in case 16 17 if atime.Before(unixMinTime) || atime.After(unixMaxTime) { 18 atime = unixMinTime 19 } 20 21 if mtime.Before(unixMinTime) || mtime.After(unixMaxTime) { 22 mtime = unixMinTime 23 } 24 25 if err := os.Chtimes(name, atime, mtime); err != nil { 26 return err 27 } 28 29 // Take platform specific action for setting create time. 30 if err := setCTime(name, mtime); err != nil { 31 return err 32 } 33 34 return nil 35 }