mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
pkg/system: windows: setCTime(): remove redundant conversion
It looks like this function was converting the time (`windows.NsecToTimespec()`), only to convert it back (`windows.TimespecToNsec()`). This became clear when moving the lines together: ```go ctimespec := windows.NsecToTimespec(ctime.UnixNano()) c := windows.NsecToFiletime(windows.TimespecToNsec(ctimespec)) ``` And looking at the Golang code, it looks like they're indeed the exact reverse: ```go func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } func NsecToTimespec(nsec int64) (ts Timespec) { ts.Sec = nsec / 1e9 ts.Nsec = nsec % 1e9 return } ``` While modifying this code, also renaming the `e` variable to a more common `err`. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
0b8444aa0c
commit
7bd051eeec
1 changed files with 7 additions and 8 deletions
|
@ -9,18 +9,17 @@ import (
|
|||
// setCTime will set the create time on a file. On Windows, this requires
|
||||
// calling SetFileTime and explicitly including the create time.
|
||||
func setCTime(path string, ctime time.Time) error {
|
||||
ctimespec := windows.NsecToTimespec(ctime.UnixNano())
|
||||
pathp, e := windows.UTF16PtrFromString(path)
|
||||
if e != nil {
|
||||
return e
|
||||
pathp, err := windows.UTF16PtrFromString(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
h, e := windows.CreateFile(pathp,
|
||||
h, err := windows.CreateFile(pathp,
|
||||
windows.FILE_WRITE_ATTRIBUTES, windows.FILE_SHARE_WRITE, nil,
|
||||
windows.OPEN_EXISTING, windows.FILE_FLAG_BACKUP_SEMANTICS, 0)
|
||||
if e != nil {
|
||||
return e
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer windows.Close(h)
|
||||
c := windows.NsecToFiletime(windows.TimespecToNsec(ctimespec))
|
||||
c := windows.NsecToFiletime(ctime.UnixNano())
|
||||
return windows.SetFileTime(h, &c, nil, nil)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue