Merge pull request #7491 from thaJeztah/chtimes_redundancy

archive: windows: chtimes(): remove redundant conversion
This commit is contained in:
Kazuyoshi Kato 2022-10-07 16:10:54 -07:00 committed by GitHub
commit 4a0ddfa974
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -25,18 +25,17 @@ import (
// chtimes will set the create time on a file using the given modtime. // chtimes will set the create time on a file using the given modtime.
// This requires calling SetFileTime and explicitly including the create time. // This requires calling SetFileTime and explicitly including the create time.
func chtimes(path string, atime, mtime time.Time) error { func chtimes(path string, atime, mtime time.Time) error {
ctimespec := windows.NsecToTimespec(mtime.UnixNano()) pathp, err := windows.UTF16PtrFromString(path)
pathp, e := windows.UTF16PtrFromString(path) if err != nil {
if e != nil { return err
return e
} }
h, e := windows.CreateFile(pathp, h, err := windows.CreateFile(pathp,
windows.FILE_WRITE_ATTRIBUTES, windows.FILE_SHARE_WRITE, nil, windows.FILE_WRITE_ATTRIBUTES, windows.FILE_SHARE_WRITE, nil,
windows.OPEN_EXISTING, windows.FILE_FLAG_BACKUP_SEMANTICS, 0) windows.OPEN_EXISTING, windows.FILE_FLAG_BACKUP_SEMANTICS, 0)
if e != nil { if err != nil {
return e return err
} }
defer windows.Close(h) defer windows.Close(h)
c := windows.NsecToFiletime(windows.TimespecToNsec(ctimespec)) c := windows.NsecToFiletime(mtime.UnixNano())
return windows.SetFileTime(h, &c, nil, nil) return windows.SetFileTime(h, &c, nil, nil)
} }