From 144257f8bd718227b985e5029ad9acc8f3cc0a51 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sun, 30 Oct 2022 11:02:31 +0100 Subject: [PATCH] restore symlink timestamps on windows --- internal/restic/node_windows.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/internal/restic/node_windows.go b/internal/restic/node_windows.go index 04a4fe62b..fc6439b40 100644 --- a/internal/restic/node_windows.go +++ b/internal/restic/node_windows.go @@ -17,7 +17,21 @@ func lchown(path string, uid int, gid int) (err error) { } func (node Node) restoreSymlinkTimestamps(path string, utimes [2]syscall.Timespec) error { - return nil + // tweaked version of UtimesNano from go/src/syscall/syscall_windows.go + pathp, e := syscall.UTF16PtrFromString(path) + if e != nil { + return e + } + h, e := syscall.CreateFile(pathp, + syscall.FILE_WRITE_ATTRIBUTES, syscall.FILE_SHARE_WRITE, nil, syscall.OPEN_EXISTING, + syscall.FILE_FLAG_BACKUP_SEMANTICS|syscall.FILE_FLAG_OPEN_REPARSE_POINT, 0) + if e != nil { + return e + } + defer syscall.Close(h) + a := syscall.NsecToFiletime(syscall.TimespecToNsec(utimes[0])) + w := syscall.NsecToFiletime(syscall.TimespecToNsec(utimes[1])) + return syscall.SetFileTime(h, nil, &a, &w) } // Getxattr retrieves extended attribute data associated with path.