[Libreoffice-commits] core.git: sal/osl

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Sat Dec 15 15:30:28 UTC 2018


 sal/osl/w32/file_url.cxx |   65 +++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 54 insertions(+), 11 deletions(-)

New commits:
commit e0def896eb9b32f95cb7b00afb92421ee51b8281
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Sat Dec 15 05:57:00 2018 +0100
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Sat Dec 15 16:30:08 2018 +0100

    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 at collabora.com>

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
                 {


More information about the Libreoffice-commits mailing list