From f09390fbf15ae4f4a7e746060c9614f5b5561921 Mon Sep 17 00:00:00 2001 From: KWSys Upstream Date: Fri, 1 Nov 2024 07:49:35 -0400 Subject: [PATCH] KWSys 2024-11-01 (1cfc8445) Code extracted from: https://gitlab.kitware.com/utils/kwsys.git at commit 1cfc8445570dc46883e84301eb6c31ebc5867826 (master). Upstream Shortlog ----------------- Brad King (1): fdf4f2f8 SystemTools: Fix ReadSymlink for links to absolute paths on Windows --- SystemTools.cxx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/SystemTools.cxx b/SystemTools.cxx index f690476824..2f42a3f4b2 100644 --- a/SystemTools.cxx +++ b/SystemTools.cxx @@ -3392,6 +3392,14 @@ Status SystemTools::ReadSymlink(std::string const& newName, } std::wstring substituteName(substituteNameData, substituteNameLength); origName = Encoding::ToNarrow(substituteName); + // Symbolic links to absolute paths may use a NT Object Path prefix. + // If the path begins with "\??\UNC\", replace it with "\\". + // Otherwise, if the path begins with "\??\", remove the prefix. + if (origName.compare(0, 8, "\\??\\UNC\\") == 0) { + origName.erase(1, 6); + } else if (origName.compare(0, 4, "\\??\\") == 0) { + origName.erase(0, 4); + } #else char buf[KWSYS_SYSTEMTOOLS_MAXPATH + 1]; int count = static_cast(