forked from OSchip/llvm-project
parent
87ee8a0adb
commit
9ada18b339
|
@ -472,13 +472,25 @@ bool __fs_is_empty(const path& p, std::error_code *ec)
|
|||
std::error_code m_ec;
|
||||
struct ::stat pst;
|
||||
auto st = detail::posix_stat(p, pst, &m_ec);
|
||||
if (is_directory(st))
|
||||
return directory_iterator(p) == directory_iterator{};
|
||||
if (m_ec) {
|
||||
set_or_throw(m_ec, ec, "is_empty", p);
|
||||
return false;
|
||||
}
|
||||
else if (!is_directory(st) && !is_regular_file(st)) {
|
||||
m_ec = make_error_code(errc::not_supported);
|
||||
set_or_throw(m_ec, ec, "is_empty");
|
||||
return false;
|
||||
}
|
||||
else if (is_directory(st)) {
|
||||
auto it = ec ? directory_iterator(p, *ec) : directory_iterator(p);
|
||||
if (ec && *ec)
|
||||
return false;
|
||||
return it == directory_iterator{};
|
||||
}
|
||||
else if (is_regular_file(st))
|
||||
return static_cast<std::uintmax_t>(pst.st_size) == 0;
|
||||
// else
|
||||
set_or_throw(m_ec, ec, "is_empty", p);
|
||||
return false;
|
||||
|
||||
_LIBCPP_UNREACHABLE();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -77,4 +77,33 @@ TEST_CASE(test_is_empty_fails)
|
|||
TEST_CHECK_THROW(filesystem_error, is_empty(dir2));
|
||||
}
|
||||
|
||||
TEST_CASE(test_directory_access_denied)
|
||||
{
|
||||
scoped_test_env env;
|
||||
const path dir = env.create_dir("dir");
|
||||
const path file1 = env.create_file("dir/file", 42);
|
||||
permissions(dir, perms::none);
|
||||
|
||||
std::error_code ec = GetTestEC();
|
||||
TEST_CHECK(is_empty(dir, ec) == false);
|
||||
TEST_CHECK(ec);
|
||||
TEST_CHECK(ec != GetTestEC());
|
||||
|
||||
TEST_CHECK_THROW(filesystem_error, is_empty(dir));
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE(test_fifo_fails)
|
||||
{
|
||||
scoped_test_env env;
|
||||
const path fifo = env.create_fifo("fifo");
|
||||
|
||||
std::error_code ec = GetTestEC();
|
||||
TEST_CHECK(is_empty(fifo, ec) == false);
|
||||
TEST_CHECK(ec);
|
||||
TEST_CHECK(ec != GetTestEC());
|
||||
|
||||
TEST_CHECK_THROW(filesystem_error, is_empty(fifo));
|
||||
}
|
||||
|
||||
TEST_SUITE_END()
|
||||
|
|
|
@ -90,7 +90,7 @@
|
|||
<tr><td><a href="http://wg21.link/LWG2598">2598</a></td><td>addressof works on temporaries</td><td>Issaquah</td><td>Patch ready</td></tr>
|
||||
<tr><td><a href="http://wg21.link/LWG2664">2664</a></td><td>operator/ (and other append) semantics not useful if argument has root</td><td>Issaquah</td><td>Nothing to do</td></tr>
|
||||
<tr><td><a href="http://wg21.link/LWG2665">2665</a></td><td>remove_filename() post condition is incorrect</td><td>Issaquah</td><td>See Below</td></tr>
|
||||
<tr><td><a href="http://wg21.link/LWG2672">2672</a></td><td>Should is_empty use error_code in its specification?</td><td>Issaquah</td><td></td></tr>
|
||||
<tr><td><a href="http://wg21.link/LWG2672">2672</a></td><td>Should is_empty use error_code in its specification?</td><td>Issaquah</td><td>We already do this</td></tr>
|
||||
<tr><td><a href="http://wg21.link/LWG2678">2678</a></td><td>std::filesystem enum classes overspecified</td><td>Issaquah</td><td>Nothing to do</td></tr>
|
||||
<tr><td><a href="http://wg21.link/LWG2679">2679</a></td><td>Inconsistent Use of Effects and Equivalent To</td><td>Issaquah</td><td>Nothing to do</td></tr>
|
||||
<tr><td><a href="http://wg21.link/LWG2680">2680</a></td><td>Add "Equivalent to" to filesystem</td><td>Issaquah</td><td></td></tr>
|
||||
|
@ -168,7 +168,7 @@
|
|||
<li>2598 - Patch and tests ready</li>
|
||||
<li>2664 - No change needed. _LIBCPP_DEBUG mode tests the new requirements.</li>
|
||||
<li>2665 - PR is incorrect as-is. We implement a modified version</li>
|
||||
<li>2672 - File System; Eric?</li>
|
||||
<li>2672 - Patch and tests in tree. </li>
|
||||
<li>2678 - File System; Eric?</li>
|
||||
<li>2679 - This is just wording cleanup. </li>
|
||||
<li>2680 - File System; Eric?</li>
|
||||
|
|
Loading…
Reference in New Issue