Correct handling of status() for reparse point when it is not a symlink.

This commit is contained in:
Roman Savchenko 2018-06-08 19:23:54 +03:00
parent ed9e019b01
commit d3e3f46ce6

View File

@ -1864,6 +1864,8 @@ file_status status(const path& p, error_code* ec)
return process_status_failure(p, ec);
}
if (ec != 0) ec->clear();
perms permissions = make_permissions(p, attr);
// reparse point handling;
@ -1871,6 +1873,12 @@ file_status status(const path& p, error_code* ec)
// handle to discover if the file exists
if (attr & FILE_ATTRIBUTE_REPARSE_POINT)
{
if (!is_reparse_point_a_symlink(p))
{
return file_status(reparse_file, permissions);
}
// try to resolve symlink
handle_wrapper h(
create_file_handle(
p.c_str(),
@ -1880,16 +1888,22 @@ file_status status(const path& p, error_code* ec)
OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS,
0)); // hTemplateFile
if (h.handle == INVALID_HANDLE_VALUE)
{
return process_status_failure(p, ec);
}
if (!is_reparse_point_a_symlink(p))
return file_status(reparse_file, permissions);
// take attributes of target
BY_HANDLE_FILE_INFORMATION info;
if (!::GetFileInformationByHandle(h.handle, &info))
{
return process_status_failure(p, ec);
}
attr = info.dwFileAttributes;
}
if (ec != 0) ec->clear();
return (attr & FILE_ATTRIBUTE_DIRECTORY)
? file_status(directory_file, permissions)
: file_status(regular_file, permissions);