2018-02-05 16:05:59 -05:00
|
|
|
package system // import "github.com/docker/docker/pkg/system"
|
2015-10-01 13:45:32 -04:00
|
|
|
|
|
|
|
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)
|
2015-11-03 17:49:50 -05:00
|
|
|
unixMaxTime := maxTime
|
2015-10-01 13:45:32 -04:00
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
2016-02-08 18:40:12 -05:00
|
|
|
// Take platform specific action for setting create time.
|
2018-01-14 18:42:25 -05:00
|
|
|
return setCTime(name, mtime)
|
2015-10-01 13:45:32 -04:00
|
|
|
}
|