github.com/a4a881d4/docker@v1.9.0-rc2/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 // The max Unix time is 33 bits set 12 unixMaxTime := unixMinTime.Add((1<<33 - 1) * time.Second) 13 14 // If the modified time is prior to the Unix Epoch, or after the 15 // end of Unix Time, os.Chtimes has undefined behavior 16 // default to Unix Epoch in this case, just in case 17 18 if atime.Before(unixMinTime) || atime.After(unixMaxTime) { 19 atime = unixMinTime 20 } 21 22 if mtime.Before(unixMinTime) || mtime.After(unixMaxTime) { 23 mtime = unixMinTime 24 } 25 26 if err := os.Chtimes(name, atime, mtime); err != nil { 27 return err 28 } 29 30 return nil 31 }