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