mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
fe5b34ba88
Signed-off-by: John Howard <jhoward@microsoft.com>
35 lines
806 B
Go
35 lines
806 B
Go
package system
|
|
|
|
import (
|
|
"os"
|
|
"time"
|
|
)
|
|
|
|
// Chtimes changes the access time and modified time of a file at the given path
|
|
func Chtimes(name string, atime time.Time, mtime time.Time) error {
|
|
unixMinTime := time.Unix(0, 0)
|
|
unixMaxTime := maxTime
|
|
|
|
// If the modified time is prior to the Unix Epoch, or after the
|
|
// end of Unix Time, os.Chtimes has undefined behavior
|
|
// default to Unix Epoch in this case, just in case
|
|
|
|
if atime.Before(unixMinTime) || atime.After(unixMaxTime) {
|
|
atime = unixMinTime
|
|
}
|
|
|
|
if mtime.Before(unixMinTime) || mtime.After(unixMaxTime) {
|
|
mtime = unixMinTime
|
|
}
|
|
|
|
if err := os.Chtimes(name, atime, mtime); err != nil {
|
|
return err
|
|
}
|
|
|
|
// Take platform specific action for setting create time.
|
|
if err := setCTime(name, mtime); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|