summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/utilcode/longfilepathwrappers.cpp29
1 files changed, 22 insertions, 7 deletions
diff --git a/src/utilcode/longfilepathwrappers.cpp b/src/utilcode/longfilepathwrappers.cpp
index 2b5a8b48a6..9ffbf27cc8 100644
--- a/src/utilcode/longfilepathwrappers.cpp
+++ b/src/utilcode/longfilepathwrappers.cpp
@@ -17,6 +17,7 @@ private:
static const WCHAR* UNCPathPrefix;
static const WCHAR* UNCExtendedPathPrefix;
static const WCHAR VolumeSeparatorChar;
+ #define UNCPATHPREFIX W("\\\\")
#endif //FEATURE_PAL
static const WCHAR LongFile::DirectorySeparatorChar;
static const WCHAR LongFile::AltDirectorySeparatorChar;
@@ -1256,7 +1257,7 @@ const WCHAR LongFile::VolumeSeparatorChar = W(':');
const WCHAR* LongFile::ExtendedPrefix = W("\\\\?\\");
const WCHAR* LongFile::DevicePathPrefix = W("\\\\.\\");
const WCHAR* LongFile::UNCExtendedPathPrefix = W("\\\\?\\UNC\\");
-const WCHAR* LongFile::UNCPathPrefix = W("\\\\");
+const WCHAR* LongFile::UNCPathPrefix = UNCPATHPREFIX;
BOOL LongFile::IsExtended(SString & path)
{
@@ -1326,7 +1327,8 @@ HRESULT LongFile::NormalizePath(SString & path)
//In this case if path is \\server the extended syntax should be like \\?\UNC\server
//The below logic populates the path from prefixLen offset from the start. This ensures that first 2 characters are overwritten
//
- prefixLen = prefix.GetCount() - 2;
+ prefixLen = prefix.GetCount() - (COUNT_T)wcslen(UNCPATHPREFIX);
+ _ASSERTE(prefixLen > 0 );
}
@@ -1366,12 +1368,25 @@ HRESULT LongFile::NormalizePath(SString & path)
}
}
+ SString fullpath(SString::Literal,buffer + prefixLen);
- //wcscpy_s always termintes with NULL, so we are saving the character that will be overwriiten
- WCHAR temp = buffer[prefix.GetCount()];
- wcscpy_s(buffer, prefix.GetCount() + 1, prefix.GetUnicode());
- buffer[prefix.GetCount()] = temp;
- path.CloseBuffer(ret + prefixLen);
+ //Check if the resolved path is a UNC. By default we assume relative path to resolve to disk
+ if (fullpath.BeginsWith(UNCPathPrefix) && prefixLen != prefix.GetCount() - (COUNT_T)wcslen(UNCPATHPREFIX))
+ {
+
+ //Remove the leading '\\' from the UNC path to be replaced with UNCExtendedPathPrefix
+ fullpath.Replace(fullpath.Begin(), (COUNT_T)wcslen(UNCPATHPREFIX), UNCExtendedPathPrefix);
+ path.CloseBuffer();
+ path.Set(fullpath);
+ }
+ else
+ {
+ //wcscpy_s always termintes with NULL, so we are saving the character that will be overwriiten
+ WCHAR temp = buffer[prefix.GetCount()];
+ wcscpy_s(buffer, prefix.GetCount() + 1, prefix.GetUnicode());
+ buffer[prefix.GetCount()] = temp;
+ path.CloseBuffer(ret + prefixLen);
+ }
return S_OK;
}