From cd76bbf256c99e0c8ba9c443b78c821daa6d605e Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Wed, 21 Feb 2018 09:27:25 +0100 Subject: Use long path prefix in osl_getFileStatus When installing an extension e.g., paths can get very long and they hit the 255 char limit, thus the installation fails. So we need to prefix the path with the long file name prefix when its longer than MAX_PATH for windows api calls to succeed. Change-Id: Ie62644192ba40a9d4802772cd9837fc84fae947a Reviewed-on: https://gerrit.libreoffice.org/50079 Tested-by: Jenkins Reviewed-by: Mike Kaganski (cherry picked from commit 50bf4eec6ff3cb3db23484331965f2e32cb0b5bc) Reviewed-on: https://gerrit.libreoffice.org/50228 --- sal/osl/w32/file_dirvol.cxx | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'sal') diff --git a/sal/osl/w32/file_dirvol.cxx b/sal/osl/w32/file_dirvol.cxx index 3ef290140a0a..947f830cc41e 100644 --- a/sal/osl/w32/file_dirvol.cxx +++ b/sal/osl/w32/file_dirvol.cxx @@ -1573,9 +1573,16 @@ oslFileError SAL_CALL osl_getFileStatus( break; } + OUString sFullPath(pItemImpl->m_pFullPath); + + // Prefix long paths, windows API calls expect this prefix + // (only local paths starting with something like C: or D:) + if (sFullPath.getLength() >= MAX_PATH && isalpha(sFullPath[0]) && sFullPath[1] == ':') + sFullPath = "\\\\?\\" + sFullPath; + if ( uFieldMask & osl_FileStatus_Mask_Validate ) { - HANDLE hFind = FindFirstFileW( o3tl::toW(rtl_uString_getStr( pItemImpl->m_pFullPath )), &pItemImpl->FindData ); + HANDLE hFind = FindFirstFileW( o3tl::toW(sFullPath.getStr() ), &pItemImpl->FindData ); if ( hFind != INVALID_HANDLE_VALUE ) FindClose( hFind ); @@ -1635,7 +1642,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; @@ -1647,7 +1654,7 @@ oslFileError SAL_CALL osl_getFileStatus( if ( !pItemImpl->bFullPathNormalized ) { ::osl::LongPathBuffer< sal_Unicode > aBuffer( MAX_LONG_PATH ); - sal_uInt32 nNewLen = GetCaseCorrectPathName( o3tl::toW(rtl_uString_getStr( pItemImpl->m_pFullPath )), + sal_uInt32 nNewLen = GetCaseCorrectPathName( o3tl::toW( sFullPath.getStr() ), o3tl::toW( aBuffer ), aBuffer.getBufSizeInSymbols(), true ); @@ -1655,11 +1662,12 @@ 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( pItemImpl->m_pFullPath, &pStatus->ustrFileURL ); + oslFileError error = osl_getFileURLFromSystemPath( sFullPath.pData, &pStatus->ustrFileURL ); if (error != osl_File_E_None) return error; pStatus->uValidFields |= osl_FileStatus_Mask_FileURL; -- cgit