Fix symlink type check on Windows

(cherry picked from commit d5332b274c)
This commit is contained in:
Martin 2017-04-04 15:01:18 +02:00
parent e821af9ef0
commit 35c552178f

View File

@ -481,29 +481,41 @@ bool isDirectory(const std::string &path, void* transaction)
}
}
int os_get_file_type(const std::string &path)
bool os_is_symlink_int(const std::string& path)
{
WIN32_FIND_DATAW wfd;
HANDLE hf = FindFirstFileW(ConvertToWchar(path).c_str(), &wfd);
if (hf == INVALID_HANDLE_VALUE)
{
return 0;
return false;
}
FindClose(hf);
int ret = 0;
if (wfd.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)
{
if (wfd.dwReserved0 == IO_REPARSE_TAG_MOUNT_POINT
|| wfd.dwReserved0 == IO_REPARSE_TAG_SYMLINK)
|| wfd.dwReserved0 == IO_REPARSE_TAG_SYMLINK)
{
ret |= EFileType_Symlink;
return true;
}
}
if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
return false;
}
int os_get_file_type(const std::string &path)
{
DWORD attrib = GetFileAttributesW(ConvertToWchar(path).c_str());
if (attrib == INVALID_FILE_ATTRIBUTES)
{
return 0;
}
int ret = 0;
if (attrib & FILE_ATTRIBUTE_DIRECTORY)
{
ret |= EFileType_Directory;
}
@ -512,6 +524,14 @@ int os_get_file_type(const std::string &path)
ret |= EFileType_File;
}
if (attrib & FILE_ATTRIBUTE_REPARSE_POINT)
{
if (os_is_symlink_int(path))
{
ret |= EFileType_Symlink;
}
}
return ret;
}