summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2018-12-15 05:57:00 +0100
committerMike Kaganski <mike.kaganski@collabora.com>2018-12-15 16:30:08 +0100
commite0def896eb9b32f95cb7b00afb92421ee51b8281 (patch)
treed0de4f875ac592d4b7eb0ecf95d7ed96617f1bdb /sal
parent07d009bb25be8334babd33564f5222a5da9e66d4 (diff)
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: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sal')
-rw-r--r--sal/osl/w32/file_url.cxx65
1 files changed, 54 insertions, 11 deletions
diff --git a/sal/osl/w32/file_url.cxx b/sal/osl/w32/file_url.cxx
index 2413efbe2dbb..b096515902ba 100644
--- a/sal/osl/w32/file_url.cxx
+++ b/sal/osl/w32/file_url.cxx
@@ -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
{