summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRama krishnan Raghupathy <ramarag@microsoft.com>2016-07-29 00:06:12 -0700
committerGitHub <noreply@github.com>2016-07-29 00:06:12 -0700
commit8a19f535d4c30243e98de7452394a4e136eefc6a (patch)
tree5b754d623a1e7fa79b063ccc7fc29f65fe48dbee /src
parent5081848ef586d34a8de1599e2f01a1b67f0466c8 (diff)
parent2eb7d0c11a2842243c34e2302997e739c18cf7d6 (diff)
downloadcoreclr-8a19f535d4c30243e98de7452394a4e136eefc6a.tar.gz
coreclr-8a19f535d4c30243e98de7452394a4e136eefc6a.tar.bz2
coreclr-8a19f535d4c30243e98de7452394a4e136eefc6a.zip
Merge pull request #6499 from ramarag/unc_cwd
Fxing the paths that are resolved relative to a network share
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;
}