github.com/Prakhar-Agarwal-byte/moby@v0.0.0-20231027092010-a14e3e8ab87e/pkg/system/chtimes_windows.go (about)

     1  package system // import "github.com/Prakhar-Agarwal-byte/moby/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  	pathp, err := windows.UTF16PtrFromString(path)
    13  	if err != nil {
    14  		return err
    15  	}
    16  	h, err := windows.CreateFile(pathp,
    17  		windows.FILE_WRITE_ATTRIBUTES, windows.FILE_SHARE_WRITE, nil,
    18  		windows.OPEN_EXISTING, windows.FILE_FLAG_BACKUP_SEMANTICS, 0)
    19  	if err != nil {
    20  		return err
    21  	}
    22  	defer windows.Close(h)
    23  	c := windows.NsecToFiletime(ctime.UnixNano())
    24  	return windows.SetFileTime(h, &c, nil, nil)
    25  }