github.com/docker/docker@v299999999.0.0-20200612211812-aaf470eca7b5+incompatible/pkg/system/chtimes_windows.go (about)

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