From 4469fe15753d6c6994a3b6e1e50a6dcd0d61164d Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Thu, 29 Aug 2024 23:22:16 +0200 Subject: [PATCH] fs: fix restoring timestamps on Windows for long paths --- changelog/unreleased/issue-1843 | 9 +++++++++ internal/fs/node.go | 2 +- internal/fs/node_windows.go | 4 ++-- 3 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 changelog/unreleased/issue-1843 diff --git a/changelog/unreleased/issue-1843 b/changelog/unreleased/issue-1843 new file mode 100644 index 000000000..1b891adc9 --- /dev/null +++ b/changelog/unreleased/issue-1843 @@ -0,0 +1,9 @@ +Bugfix: Correctly restore timestamp on long filepaths on old Windows versions + +The `restore` command did not restore timestamps on file paths longer than 256 +characters on Windows versions before Windows 10 1607. + +This issue is now resolved. + +https://github.com/restic/restic/issues/1843 +https://github.com/restic/restic/pull/5061 diff --git a/internal/fs/node.go b/internal/fs/node.go index 280e290c2..a273a9f08 100644 --- a/internal/fs/node.go +++ b/internal/fs/node.go @@ -315,7 +315,7 @@ func nodeRestoreTimestamps(node *restic.Node, path string) error { return nodeRestoreSymlinkTimestamps(path, utimes) } - if err := syscall.UtimesNano(path, utimes[:]); err != nil { + if err := syscall.UtimesNano(fixpath(path), utimes[:]); err != nil { return errors.Wrap(err, "UtimesNano") } diff --git a/internal/fs/node_windows.go b/internal/fs/node_windows.go index 9d46143cc..836e7b5d4 100644 --- a/internal/fs/node_windows.go +++ b/internal/fs/node_windows.go @@ -202,7 +202,7 @@ func genericAttributesToWindowsAttrs(attrs map[restic.GenericAttributeType]json. // restoreCreationTime gets the creation time from the data and sets it to the file/folder at // the specified path. func restoreCreationTime(path string, creationTime *syscall.Filetime) (err error) { - pathPointer, err := syscall.UTF16PtrFromString(path) + pathPointer, err := syscall.UTF16PtrFromString(fixpath(path)) if err != nil { return err } @@ -223,7 +223,7 @@ func restoreCreationTime(path string, creationTime *syscall.Filetime) (err error // restoreFileAttributes gets the File Attributes from the data and sets them to the file/folder // at the specified path. func restoreFileAttributes(path string, fileAttributes *uint32) (err error) { - pathPointer, err := syscall.UTF16PtrFromString(path) + pathPointer, err := syscall.UTF16PtrFromString(fixpath(path)) if err != nil { return err }