chtimes_windows.go 701 B

12345678910111213141516171819202122232425
  1. package system // import "github.com/docker/docker/pkg/system"
  2. import (
  3. "time"
  4. "golang.org/x/sys/windows"
  5. )
  6. // setCTime will set the create time on a file. On Windows, this requires
  7. // calling SetFileTime and explicitly including the create time.
  8. func setCTime(path string, ctime time.Time) error {
  9. pathp, err := windows.UTF16PtrFromString(path)
  10. if err != nil {
  11. return err
  12. }
  13. h, err := windows.CreateFile(pathp,
  14. windows.FILE_WRITE_ATTRIBUTES, windows.FILE_SHARE_WRITE, nil,
  15. windows.OPEN_EXISTING, windows.FILE_FLAG_BACKUP_SEMANTICS, 0)
  16. if err != nil {
  17. return err
  18. }
  19. defer windows.Close(h)
  20. c := windows.NsecToFiletime(ctime.UnixNano())
  21. return windows.SetFileTime(h, &c, nil, nil)
  22. }