mirror of
https://github.com/uroni/urbackup_backend.git
synced 2025-10-26 11:36:50 +00:00
Fix symlink type check on Windows
(cherry picked from commit d5332b274c)
This commit is contained in:
parent
e821af9ef0
commit
35c552178f
@ -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;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user