refs #107, fix handling of inaccessible symlink target errors

This commit is contained in:
Steffen Schuemann 2021-03-14 10:45:10 +01:00
parent 0858444609
commit 8d45dc4d41

View File

@ -2227,6 +2227,13 @@ GHC_INLINE file_status status_ex(const path& p, std::error_code& ec, file_status
if (result == 0) { if (result == 0) {
fs = detail::file_status_from_st_mode(st.st_mode); fs = detail::file_status_from_st_mode(st.st_mode);
} }
else {
ec = detail::make_system_error();
if (detail::is_not_found_error(ec)) {
return file_status(file_type::not_found, perms::unknown);
}
return file_status(file_type::none);
}
} }
if (sz) { if (sz) {
*sz = static_cast<uintmax_t>(st.st_size); *sz = static_cast<uintmax_t>(st.st_size);
@ -4661,23 +4668,22 @@ GHC_INLINE uintmax_t remove_all(const path& p, std::error_code& ec) noexcept
auto fs = status(p, tec); auto fs = status(p, tec);
if (exists(fs) && is_directory(fs)) { if (exists(fs) && is_directory(fs)) {
for (auto iter = directory_iterator(p, ec); iter != directory_iterator(); iter.increment(ec)) { for (auto iter = directory_iterator(p, ec); iter != directory_iterator(); iter.increment(ec)) {
if (ec) { if (ec && !detail::is_not_found_error(ec)) {
break; break;
} }
bool is_symlink_result = iter->is_symlink(ec); bool is_symlink_result = iter->is_symlink(ec);
if (ec) if (ec)
return static_cast<uintmax_t>(-1); return static_cast<uintmax_t>(-1);
bool is_directory_result = iter->is_directory(ec); if (!is_symlink_result && iter->is_directory(ec)) {
if (ec)
return static_cast<uintmax_t>(-1);
if (!is_symlink_result && is_directory_result) {
count += remove_all(iter->path(), ec); count += remove_all(iter->path(), ec);
if (ec) { if (ec) {
return static_cast<uintmax_t>(-1); return static_cast<uintmax_t>(-1);
} }
} }
else { else {
if (!ec) {
remove(iter->path(), ec); remove(iter->path(), ec);
}
if (ec) { if (ec) {
return static_cast<uintmax_t>(-1); return static_cast<uintmax_t>(-1);
} }