Kaydet (Commit) e0def896 authored tarafından Mike Kaganski's avatar Mike Kaganski

tdf#98343 follow-up: don't fail on UNC prefixes

Previously, it used to use FindFirstFile on initial parts of UNC paths,
and failed, failing the whole path.

Change-Id: Ibc4442e28da17625676695070ed7ddba619f9082
Reviewed-on: https://gerrit.libreoffice.org/65191
Tested-by: Jenkins
Reviewed-by: 's avatarMike Kaganski <mike.kaganski@collabora.com>
üst 07d009bb
......@@ -362,6 +362,38 @@ static LPWSTR PathAddBackslash(LPWSTR lpPath, sal_uInt32 nBufLen)
return lpEndPath;
}
// True if the szPath + szFile is just a special prefix, not a path which we may test for existence.
// E.g., \\ or \\server or \\server\share or \\? or \\?\UNC or \\?\UNC\server or \\?\UNC\server\share
static bool IsPathSpecialPrefix(LPWSTR szPath, LPWSTR szFile)
{
if (szPath[0] == '\\' && szPath[1] == '\\')
{
if (szPath[2] == 0)
return true; // "\\" -> now the server name or "." or "?" will append
else if (szPath[2] == '?' && szPath[3] == '\\')
{
if (szPath[4] == 0)
return wcscmp(szFile, L"UNC") == 0; // "\\?\" -> now "UNC" will append
else
{
if (wcsncmp(szPath + 4, L"UNC\\", 4) == 0)
{
if (szPath[8] == 0)
return true; // "\\?\UNC\" -> now the server name will append
else if (const wchar_t* pBackSlash = wcschr(szPath + 8, '\\'))
return *(pBackSlash + 1) == 0; // "\\?\UNC\Server\" -> now share name will append
}
}
}
else if (szPath[2] != '.')
{
if (const wchar_t* pBackSlash = wcschr(szPath + 2, '\\'))
return *(pBackSlash + 1) == 0; // "\\Server\" -> now share name will append
}
}
return false;
}
// Expects a proper absolute or relative path. NB: It is different from GetLongPathName WinAPI!
static DWORD GetCaseCorrectPathNameEx(
LPWSTR lpszPath, // path buffer to convert
......@@ -410,21 +442,32 @@ static DWORD GetCaseCorrectPathNameEx(
{
if ( bCheckExistence )
{
::osl::LongPathBuffer< WCHAR > aShortPath( MAX_LONG_PATH );
wcscpy( aShortPath, lpszPath );
wcscat( aShortPath, szFile );
WIN32_FIND_DATAW aFindFileData;
HANDLE hFind = FindFirstFileW( aShortPath, &aFindFileData );
if ( IsValidHandle(hFind) )
if (IsPathSpecialPrefix(lpszPath, szFile))
{
wcscat( lpszPath, aFindFileData.cFileName[0] ? aFindFileData.cFileName : aFindFileData.cAlternateFileName );
FindClose( hFind );
/* add the segment name back */
wcscat(lpszPath, szFile);
}
else
lpszPath[0] = 0;
{
osl::LongPathBuffer<WCHAR> aShortPath(MAX_LONG_PATH);
wcscpy(aShortPath, lpszPath);
wcscat(aShortPath, szFile);
WIN32_FIND_DATAW aFindFileData;
HANDLE hFind = FindFirstFileW(aShortPath, &aFindFileData);
if (IsValidHandle(hFind))
{
wcscat(lpszPath, aFindFileData.cFileName[0]
? aFindFileData.cFileName
: aFindFileData.cAlternateFileName);
FindClose(hFind);
}
else
lpszPath[0] = 0;
}
}
else
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment