From 9043b32bb1835628c5a1d8be4a271c848443c629 Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Tue, 24 May 2016 22:10:57 +0200 Subject: 8.1 --- zen/symlink_target.h | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'zen/symlink_target.h') diff --git a/zen/symlink_target.h b/zen/symlink_target.h index f50d1806..c4e166e8 100644 --- a/zen/symlink_target.h +++ b/zen/symlink_target.h @@ -135,7 +135,7 @@ Zstring getSymlinkRawTargetString_impl(const Zstring& linkPath) //throw FileErro throw FileError(replaceCpy(_("Cannot resolve symbolic link %x."), L"%x", fmtPath(linkPath)), L"Not a symbolic link or junction."); //absolute symlinks and junctions use NT namespace naming convention while relative ones do not: - //http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx#NT_Namespaces + //https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247#NT_Namespaces return ntPathToWin32Path(output); #elif defined ZEN_LINUX || defined ZEN_MAC @@ -158,7 +158,7 @@ Zstring getResolvedSymlinkPath_impl(const Zstring& linkPath) //throw FileError using namespace zen; #ifdef ZEN_WIN //GetFinalPathNameByHandle() is not available before Vista! - typedef DWORD (WINAPI* GetFinalPathNameByHandleWFunc)(HANDLE hFile, LPTSTR lpszFilePath, DWORD cchFilePath, DWORD dwFlags); + using GetFinalPathNameByHandleWFunc = DWORD (WINAPI*)(HANDLE hFile, LPTSTR lpszFilePath, DWORD cchFilePath, DWORD dwFlags); const SysDllFun getFinalPathNameByHandle(L"kernel32.dll", "GetFinalPathNameByHandleW"); if (!getFinalPathNameByHandle) throw FileError(replaceCpy(_("Cannot determine final path for %x."), L"%x", fmtPath(linkPath)), replaceCpy(_("Cannot find system function %x."), L"%x", L"\"GetFinalPathNameByHandleW\"")); @@ -184,15 +184,12 @@ Zstring getResolvedSymlinkPath_impl(const Zstring& linkPath) //throw FileError &targetPath[0], //__out LPTSTR lpszFilePath, bufferSize, //__in DWORD cchFilePath, 0); //__in DWORD dwFlags - if (charsWritten == 0 || charsWritten >= bufferSize) - { - const std::wstring errorMsg = replaceCpy(_("Cannot determine final path for %x."), L"%x", fmtPath(linkPath)); - if (charsWritten == 0) - THROW_LAST_FILE_ERROR(errorMsg, L"GetFinalPathNameByHandle"); - throw FileError(errorMsg); - } + if (charsWritten == 0) + THROW_LAST_FILE_ERROR(replaceCpy(_("Cannot determine final path for %x."), L"%x", fmtPath(linkPath)), L"GetFinalPathNameByHandle"); + if (charsWritten >= bufferSize) + throw FileError(replaceCpy(_("Cannot determine final path for %x."), L"%x", fmtPath(linkPath)), L"GetFinalPathNameByHandle: buffer overflow."); - return Zstring(&targetPath[0], charsWritten); + return removeLongPathPrefix(Zstring(&targetPath[0], charsWritten)); //MSDN: GetFinalPathNameByHandle() always prepends "\\?\" #elif defined ZEN_LINUX || defined ZEN_MAC char* targetPath = ::realpath(linkPath.c_str(), nullptr); -- cgit