sal/osl/w32/file_dirvol.cxx |   28 ++++++++++++----------------
 1 file changed, 12 insertions(+), 16 deletions(-)

New commits:
commit 85c640f19f6a5b0ea34236141db37f2967b986ea
Author: Samuel Mehrbrodt <samuel.mehrbr...@cib.de>
Date:   Thu Feb 22 09:03:08 2018 +0100

    Use long path prefix in osl_getFileStatus
    
    Follow-up fixes after 51afd886e59e519be0546c980dcc724d771fd245
    
    Change-Id: I29ce4af850978322cab60743119a02d47305e739

diff --git a/sal/osl/w32/file_dirvol.cxx b/sal/osl/w32/file_dirvol.cxx
index ed6adb974365..bf9e88abf84c 100644
--- a/sal/osl/w32/file_dirvol.cxx
+++ b/sal/osl/w32/file_dirvol.cxx
@@ -43,8 +43,6 @@ static const wchar_t UNC_PREFIX[] = L"\\\\";
 static const wchar_t BACKSLASH = '\\';
 static const wchar_t SLASH = '/';
 
-#define STR_LONG_PATH_PREFIX "\\\\?\\"
-
 extern "C" BOOL TimeValueToFileTime(const TimeValue *cpTimeVal, FILETIME 
*pFTime)
 {
     SYSTEMTIME  BaseSysTime;
@@ -1587,14 +1585,6 @@ oslFileError SAL_CALL osl_getFileStatus(
     if ( !pItemImpl )
         return osl_File_E_INVAL;
 
-    // Provide a long path version of the file name, because when
-    // the path is longer than 255 chars, windows api calls expect this prefix.
-    rtl_uString* sPrefix = nullptr;
-    rtl_uString* sLongPath = nullptr;
-    rtl_uString_newFromAscii( &sPrefix, STR_LONG_PATH_PREFIX );
-    rtl_uString_newConcat( &sLongPath, sPrefix, pItemImpl->m_pFullPath );
-    rtl_uString_release( sPrefix );
-
     switch ( pItemImpl->uType  )
     {
     case DIRECTORYITEM_DRIVE:
@@ -1605,9 +1595,16 @@ oslFileError SAL_CALL osl_getFileStatus(
         break;
     }
 
+    // Provide a long path version of the file name, because when
+    // the path is longer than 255 chars, windows api calls expect this prefix.
+    OUString sFullPath(pItemImpl->m_pFullPath);
+
+    if (sFullPath.getLength() >= MAX_PATH && isalpha(sFullPath[0]) && 
sFullPath[1] == ':')
+        sFullPath = "\\\\?\\" + sFullPath;
+
     if ( uFieldMask & osl_FileStatus_Mask_Validate )
     {
-        HANDLE  hFind = FindFirstFile( rtl_uString_getStr( sLongPath ), 
&pItemImpl->FindData );
+        HANDLE  hFind = FindFirstFile( sFullPath.getStr(), 
&pItemImpl->FindData );
 
         if ( hFind != INVALID_HANDLE_VALUE )
             FindClose( hFind );
@@ -1667,7 +1664,7 @@ oslFileError SAL_CALL osl_getFileStatus(
 
     if ( uFieldMask & osl_FileStatus_Mask_LinkTargetURL )
     {
-        oslFileError error = osl_getFileURLFromSystemPath( 
pItemImpl->m_pFullPath, &pStatus->ustrLinkTargetURL );
+        oslFileError error = osl_getFileURLFromSystemPath( sFullPath.pData, 
&pStatus->ustrLinkTargetURL );
         if (error != osl_File_E_None)
             return error;
 
@@ -1679,7 +1676,7 @@ oslFileError SAL_CALL osl_getFileStatus(
         if ( !pItemImpl->bFullPathNormalized )
         {
             ::osl::LongPathBuffer< sal_Unicode > aBuffer( MAX_LONG_PATH );
-            sal_uInt32 nNewLen = GetCaseCorrectPathName( rtl_uString_getStr( 
sLongPath ),
+            sal_uInt32 nNewLen = GetCaseCorrectPathName( sFullPath.getStr(),
                                                       
::osl::mingw_reinterpret_cast<LPWSTR>( aBuffer ),
                                                       
aBuffer.getBufSizeInSymbols(),
                                                       sal_True );
@@ -1687,18 +1684,17 @@ oslFileError SAL_CALL osl_getFileStatus(
             if ( nNewLen )
             {
                 rtl_uString_newFromStr( &pItemImpl->m_pFullPath, aBuffer );
+                sFullPath = OUString( pItemImpl->m_pFullPath );
                 pItemImpl->bFullPathNormalized = TRUE;
             }
         }
 
-        oslFileError error = osl_getFileURLFromSystemPath( sLongPath, 
&pStatus->ustrFileURL );
+        oslFileError error = osl_getFileURLFromSystemPath( sFullPath.pData, 
&pStatus->ustrFileURL );
         if (error != osl_File_E_None)
             return error;
         pStatus->uValidFields |= osl_FileStatus_Mask_FileURL;
     }
 
-    rtl_uString_release( sLongPath );
-
     return osl_File_E_None;
 }
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to