summaryrefslogtreecommitdiff
path: root/src/utilcode
diff options
context:
space:
mode:
authorRama Krishnan Raghupathy <ramarag@microsoft.com>2016-07-27 18:48:24 -0700
committerRama Krishnan Raghupathy <ramarag@microsoft.com>2016-07-28 14:12:23 -0700
commit2eb7d0c11a2842243c34e2302997e739c18cf7d6 (patch)
treee188e12bb6b66f5e67b5325920b5c20acd8a35a6 /src/utilcode
parent50d9704c7918ef6adbfe9b5f10619f0dddd58cc6 (diff)
downloadcoreclr-2eb7d0c11a2842243c34e2302997e739c18cf7d6.tar.gz
coreclr-2eb7d0c11a2842243c34e2302997e739c18cf7d6.tar.bz2
coreclr-2eb7d0c11a2842243c34e2302997e739c18cf7d6.zip
Fxing the paths that are resolved relative to a network share
Diffstat (limited to 'src/utilcode')
-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;
}