1package system // import "github.com/docker/docker/pkg/system"
2
3import (
4	"os"
5	"time"
6)
7
8// Chtimes changes the access time and modified time of a file at the given path
9func 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	return setCTime(name, mtime)
31}
32