2022-05-25 01:06:16 +08:00
|
|
|
//go:build windows
|
|
|
|
|
|
|
|
package local
|
|
|
|
|
|
|
|
import (
|
|
|
|
"syscall"
|
2022-08-05 23:35:41 +08:00
|
|
|
"time"
|
2022-05-25 01:06:16 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
const haveSetBTime = true
|
|
|
|
|
2024-11-15 00:20:06 +08:00
|
|
|
// setBTime sets the birth time of the file passed in
|
|
|
|
func setBTime(name string, btime time.Time) (err error) {
|
2024-02-28 01:12:07 +08:00
|
|
|
pathp, err := syscall.UTF16PtrFromString(name)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
h, err := syscall.CreateFile(pathp,
|
|
|
|
syscall.FILE_WRITE_ATTRIBUTES, syscall.FILE_SHARE_WRITE, nil,
|
2024-11-15 00:20:06 +08:00
|
|
|
syscall.OPEN_EXISTING, syscall.FILE_FLAG_BACKUP_SEMANTICS, 0)
|
2022-05-25 01:06:16 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
closeErr := syscall.Close(h)
|
|
|
|
if err == nil {
|
|
|
|
err = closeErr
|
|
|
|
}
|
|
|
|
}()
|
2024-11-15 00:20:06 +08:00
|
|
|
bFileTime := syscall.NsecToFiletime(btime.UnixNano())
|
|
|
|
return syscall.SetFileTime(h, &bFileTime, nil, nil)
|
2022-05-25 01:06:16 +08:00
|
|
|
}
|