github.com/ssdev-go/moby@v17.12.1-ce-rc2+incompatible/pkg/system/chtimes_windows.go (about)

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