diff options
author | Kunal Pawar <hellokunalpawar@gmail.com> | 2022-02-18 19:15:04 +0530 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2022-03-04 17:00:48 +0100 |
commit | 92e835dbf00590c9c29509d2995cc7918a9bbb90 (patch) | |
tree | 4ee43eb4799cbe0b1da08f2175547d0c2f89e640 /sal/osl | |
parent | 3db91487e57277f75d64d95d06d4ddcc29f1c4e0 (diff) |
tdf#98705 Replace GetCaseCorrectPathName with GetLongPathNameW
Change-Id: I1d03267cd67da4c155248b585ca59dc5191d28f9
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130144
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sal/osl')
-rw-r--r-- | sal/osl/w32/file_dirvol.cxx | 18 | ||||
-rw-r--r-- | sal/osl/w32/file_url.cxx | 133 | ||||
-rw-r--r-- | sal/osl/w32/file_url.hxx | 7 |
3 files changed, 15 insertions, 143 deletions
diff --git a/sal/osl/w32/file_dirvol.cxx b/sal/osl/w32/file_dirvol.cxx index d0d5616678fb..f5995f8de391 100644 --- a/sal/osl/w32/file_dirvol.cxx +++ b/sal/osl/w32/file_dirvol.cxx @@ -1590,14 +1590,22 @@ oslFileError SAL_CALL osl_getFileStatus( { if ( !pItemImpl->bFullPathNormalized ) { - ::osl::LongPathBuffer< sal_Unicode > aBuffer( MAX_LONG_PATH ); - sal_uInt32 nNewLen = GetCaseCorrectPathName( o3tl::toW( sFullPath.getStr() ), - o3tl::toW( aBuffer ), - aBuffer.getBufSizeInSymbols(), - true ); + ::osl::LongPathBuffer<sal_Unicode> aBuffer(MAX_LONG_PATH); + sal_uInt32 nNewLen = GetLongPathNameW(o3tl::toW(sFullPath.getStr()), o3tl::toW(aBuffer), + aBuffer.getBufSizeInSymbols()); if ( nNewLen ) { + /* Capitalizes drive name (single letter). Windows file paths are processed + case-sensitively. While parsing a path, function osl_DirectoryItem has case + PATHTYPE_VOLUME for drives, and capatalizes them. That can be overwritten by + function osl_getFileStatus, in it win32 api GetLongPathNameW does no + capatilization. Thus it needs to be postprocessed.*/ + sal_Int32 nIndex = rtl_ustr_indexOfChar(aBuffer, ':'); + if (nIndex > 0) { + aBuffer[nIndex - 1] = rtl::toAsciiUpperCase(aBuffer[nIndex - 1]); + } + pItemImpl->m_sFullPath = OUString(&*aBuffer, nNewLen); sFullPath = pItemImpl->m_sFullPath; pItemImpl->bFullPathNormalized = true; diff --git a/sal/osl/w32/file_url.cxx b/sal/osl/w32/file_url.cxx index a8d1644b7daa..1fcdc1728696 100644 --- a/sal/osl/w32/file_url.cxx +++ b/sal/osl/w32/file_url.cxx @@ -542,134 +542,6 @@ static bool IsPathSpecialPrefix(LPWSTR szPath, LPWSTR szFile) 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 - sal_uInt32 cchBuffer, // size of path buffer - DWORD nSkipLevels, - bool bCheckExistence ) -{ - ::osl::LongPathBuffer< WCHAR > szFile( MAX_PATH + 1 ); - sal_Int32 nRemoved = PathRemoveFileSpec( lpszPath, szFile, MAX_PATH + 1 ); - sal_Int32 nLastStepRemoved = nRemoved; - while ( nLastStepRemoved && szFile[0] == 0 ) - { - // remove separators - nLastStepRemoved = PathRemoveFileSpec( lpszPath, szFile, MAX_PATH + 1 ); - nRemoved += nLastStepRemoved; - } - - if ( nRemoved ) - { - bool bSkipThis = false; - - if ( 0 == wcscmp( szFile, L".." ) ) - { - bSkipThis = true; - nSkipLevels += 1; - } - else if ( 0 == wcscmp( szFile, L"." ) ) - { - bSkipThis = true; - } - else if ( nSkipLevels ) - { - bSkipThis = true; - nSkipLevels--; - } - else - bSkipThis = false; - - if ( !GetCaseCorrectPathNameEx( lpszPath, cchBuffer, nSkipLevels, bCheckExistence ) ) - return 0; - - PathAddBackslash( lpszPath, cchBuffer ); - - /* Analyze parent if not only a trailing backslash was cut but a real file spec */ - if ( !bSkipThis ) - { - if ( bCheckExistence ) - { - - if (IsPathSpecialPrefix(lpszPath, szFile)) - { - /* add the segment name back */ - wcscat(lpszPath, szFile); - } - else - { - 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 - { - /* add the segment name back */ - wcscat( lpszPath, szFile ); - } - } - } - else - { - /* File specification can't be removed therefore the short path is either a drive - or a network share. If still levels to skip are left, the path specification - tries to travel below the file system root */ - if ( nSkipLevels ) - lpszPath[0] = 0; - else - _wcsupr( lpszPath ); - } - - return wcslen( lpszPath ); -} - -DWORD GetCaseCorrectPathName( - LPCWSTR lpszShortPath, // file name - LPWSTR lpszLongPath, // path buffer - sal_uInt32 cchBuffer, // size of path buffer - bool bCheckExistence -) -{ - /* Special handling for "\\.\" as system root */ - if ( lpszShortPath && 0 == wcscmp( lpszShortPath, o3tl::toW(WSTR_SYSTEM_ROOT_PATH) ) ) - { - if ( cchBuffer >= SAL_N_ELEMENTS(WSTR_SYSTEM_ROOT_PATH) ) - { - wcscpy( lpszLongPath, o3tl::toW(WSTR_SYSTEM_ROOT_PATH) ); - return SAL_N_ELEMENTS(WSTR_SYSTEM_ROOT_PATH) - 1; - } - else - { - return SAL_N_ELEMENTS(WSTR_SYSTEM_ROOT_PATH) - 1; - } - } - else if ( lpszShortPath ) - { - if ( wcslen( lpszShortPath ) <= cchBuffer ) - { - wcscpy( lpszLongPath, lpszShortPath ); - return GetCaseCorrectPathNameEx( lpszLongPath, cchBuffer, 0, bCheckExistence ); - } - } - - return 0; -} - static std::optional<OUString> osl_decodeURL_(const OString& sUTF8) { const char *pSrcEnd; @@ -841,10 +713,9 @@ oslFileError osl_getSystemPathFromFileURL_( rtl_uString *strURL, rtl_uString **p else { ::osl::LongPathBuffer< sal_Unicode > aBuf( MAX_LONG_PATH ); - sal_uInt32 nNewLen = GetCaseCorrectPathName( o3tl::toW(sDecodedURL->getStr()) + nSkip, + sal_uInt32 nNewLen = GetLongPathNameW( o3tl::toW(sDecodedURL->getStr()) + nSkip, o3tl::toW(aBuf), - aBuf.getBufSizeInSymbols(), - false ); + aBuf.getBufSizeInSymbols() ); if ( nNewLen <= MAX_PATH - 12 || sDecodedURL->matchIgnoreAsciiCase(WSTR_SYSTEM_ROOT_PATH, nSkip) diff --git a/sal/osl/w32/file_url.hxx b/sal/osl/w32/file_url.hxx index 22ad1b89af81..d5d5c6952cd6 100644 --- a/sal/osl/w32/file_url.hxx +++ b/sal/osl/w32/file_url.hxx @@ -52,13 +52,6 @@ DWORD IsValidFilePath ( rtl_uString ** corrected ); -DWORD GetCaseCorrectPathName ( - LPCWSTR lpszShortPath, // file name - LPWSTR lpszLongPath, // path buffer - sal_uInt32 cchBuffer, // size of path buffer - bool bCheckExistence -); - oslFileError osl_getSystemPathFromFileURL_ ( rtl_uString * strURL, rtl_uString ** pustrPath, |