@@ -17,6 +17,7 @@ class LongFile
17
17
static const WCHAR* UNCPathPrefix;
18
18
static const WCHAR* UNCExtendedPathPrefix;
19
19
static const WCHAR VolumeSeparatorChar;
20
+ #define UNCPATHPREFIX W (" \\\\ " )
20
21
#endif // FEATURE_PAL
21
22
static const WCHAR LongFile::DirectorySeparatorChar;
22
23
static const WCHAR LongFile::AltDirectorySeparatorChar;
@@ -1256,7 +1257,7 @@ const WCHAR LongFile::VolumeSeparatorChar = W(':');
1256
1257
const WCHAR* LongFile::ExtendedPrefix = W(" \\\\ ?\\ " );
1257
1258
const WCHAR* LongFile::DevicePathPrefix = W(" \\\\ .\\ " );
1258
1259
const WCHAR* LongFile::UNCExtendedPathPrefix = W(" \\\\ ?\\ UNC\\ " );
1259
- const WCHAR* LongFile::UNCPathPrefix = W( " \\\\ " ) ;
1260
+ const WCHAR* LongFile::UNCPathPrefix = UNCPATHPREFIX ;
1260
1261
1261
1262
BOOL LongFile::IsExtended (SString & path)
1262
1263
{
@@ -1326,7 +1327,8 @@ HRESULT LongFile::NormalizePath(SString & path)
1326
1327
// In this case if path is \\server the extended syntax should be like \\?\UNC\server
1327
1328
// The below logic populates the path from prefixLen offset from the start. This ensures that first 2 characters are overwritten
1328
1329
//
1329
- prefixLen = prefix.GetCount () - 2 ;
1330
+ prefixLen = prefix.GetCount () - (COUNT_T)wcslen (UNCPATHPREFIX);
1331
+ _ASSERTE (prefixLen > 0 );
1330
1332
}
1331
1333
1332
1334
@@ -1366,12 +1368,25 @@ HRESULT LongFile::NormalizePath(SString & path)
1366
1368
}
1367
1369
}
1368
1370
1371
+ SString fullpath (SString::Literal,buffer + prefixLen);
1369
1372
1370
- // wcscpy_s always termintes with NULL, so we are saving the character that will be overwriiten
1371
- WCHAR temp = buffer[prefix.GetCount ()];
1372
- wcscpy_s (buffer, prefix.GetCount () + 1 , prefix.GetUnicode ());
1373
- buffer[prefix.GetCount ()] = temp;
1374
- path.CloseBuffer (ret + prefixLen);
1373
+ // Check if the resolved path is a UNC. By default we assume relative path to resolve to disk
1374
+ if (fullpath.BeginsWith (UNCPathPrefix) && prefixLen != prefix.GetCount () - (COUNT_T)wcslen (UNCPATHPREFIX))
1375
+ {
1376
+
1377
+ // Remove the leading '\\' from the UNC path to be replaced with UNCExtendedPathPrefix
1378
+ fullpath.Replace (fullpath.Begin (), (COUNT_T)wcslen (UNCPATHPREFIX), UNCExtendedPathPrefix);
1379
+ path.CloseBuffer ();
1380
+ path.Set (fullpath);
1381
+ }
1382
+ else
1383
+ {
1384
+ // wcscpy_s always termintes with NULL, so we are saving the character that will be overwriiten
1385
+ WCHAR temp = buffer[prefix.GetCount ()];
1386
+ wcscpy_s (buffer, prefix.GetCount () + 1 , prefix.GetUnicode ());
1387
+ buffer[prefix.GetCount ()] = temp;
1388
+ path.CloseBuffer (ret + prefixLen);
1389
+ }
1375
1390
1376
1391
return S_OK;
1377
1392
}
0 commit comments