From 03aad742d3f4d46e5e6245e9ff765b7e53e1b2f9 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Thu, 31 Oct 2024 21:44:34 +0100 Subject: [PATCH] fs: add correct vss support to fixpath Paths that only contain the volume shadow copy snapshot name require special treatment. These paths must end with a slash for regular file operations to work. --- internal/fs/file_windows.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/internal/fs/file_windows.go b/internal/fs/file_windows.go index 7fb53e658..d7aabf360 100644 --- a/internal/fs/file_windows.go +++ b/internal/fs/file_windows.go @@ -21,6 +21,15 @@ func fixpath(name string) string { if strings.HasPrefix(abspath, uncPathPrefix) { return abspath } + // Check if \\?\GLOBALROOT exists which marks volume shadow copy snapshots + if strings.HasPrefix(abspath, globalRootPrefix) { + if strings.Count(abspath, `\`) == 5 { + // Append slash if this just a volume name, e.g. `\\?\GLOBALROOT\Device\HarddiskVolumeShadowCopyXX` + // Without the trailing slash any access to the volume itself will fail. + return abspath + string(filepath.Separator) + } + return abspath + } // Check if \\?\ already exist if strings.HasPrefix(abspath, extendedPathPrefix) { return abspath