2018-02-05 16:05:59 -05:00
|
|
|
package system // import "github.com/docker/docker/pkg/system"
|
2016-02-08 18:40:12 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
2017-05-23 10:22:32 -04:00
|
|
|
|
|
|
|
"golang.org/x/sys/windows"
|
2016-02-08 18:40:12 -05:00
|
|
|
)
|
|
|
|
|
2019-11-27 09:38:17 -05:00
|
|
|
// setCTime will set the create time on a file. On Windows, this requires
|
|
|
|
// calling SetFileTime and explicitly including the create time.
|
2016-02-08 18:40:12 -05:00
|
|
|
func setCTime(path string, ctime time.Time) error {
|
2017-05-23 10:22:32 -04:00
|
|
|
ctimespec := windows.NsecToTimespec(ctime.UnixNano())
|
|
|
|
pathp, e := windows.UTF16PtrFromString(path)
|
2016-02-08 18:40:12 -05:00
|
|
|
if e != nil {
|
|
|
|
return e
|
|
|
|
}
|
2017-05-23 10:22:32 -04:00
|
|
|
h, e := windows.CreateFile(pathp,
|
|
|
|
windows.FILE_WRITE_ATTRIBUTES, windows.FILE_SHARE_WRITE, nil,
|
|
|
|
windows.OPEN_EXISTING, windows.FILE_FLAG_BACKUP_SEMANTICS, 0)
|
2016-02-08 18:40:12 -05:00
|
|
|
if e != nil {
|
|
|
|
return e
|
|
|
|
}
|
2017-05-23 10:22:32 -04:00
|
|
|
defer windows.Close(h)
|
|
|
|
c := windows.NsecToFiletime(windows.TimespecToNsec(ctimespec))
|
|
|
|
return windows.SetFileTime(h, &c, nil, nil)
|
2016-02-08 18:40:12 -05:00
|
|
|
}
|