libstdc++: Add more tests for filesystem::create_directory [PR101510]

Signed-off-by: Jonathan Wakely <jwakely@redhat.com>

libstdc++-v3/ChangeLog:

	PR libstdc++/101510
	* src/c++17/fs_ops.cc (create_dir): Adjust whitespace.
	* testsuite/27_io/filesystem/operations/create_directory.cc:
	Test creating directory with name of existing symlink to
	directory.
	* testsuite/experimental/filesystem/operations/create_directory.cc:
	Likewise.
This commit is contained in:
Jonathan Wakely 2021-07-20 12:35:37 +01:00
parent 7cc2df084b
commit 0c4ae4ff46
3 changed files with 56 additions and 2 deletions

View File

@ -577,8 +577,7 @@ namespace
{
bool created = false;
#ifdef _GLIBCXX_HAVE_SYS_STAT_H
posix::mode_t mode
= static_cast<std::underlying_type_t<fs::perms>>(perm);
posix::mode_t mode = static_cast<std::underlying_type_t<fs::perms>>(perm);
if (posix::mkdir(p.c_str(), mode))
{
const int err = errno;

View File

@ -54,6 +54,33 @@ test01()
b = create_directory(p);
VERIFY( !b );
auto f = p/"file";
std::ofstream{f} << "create file";
b = create_directory(f, ec);
VERIFY( ec == std::errc::file_exists );
VERIFY( !b );
try
{
create_directory(f);
VERIFY( false );
}
catch (const fs::filesystem_error& e)
{
VERIFY( e.code() == std::errc::file_exists );
VERIFY( e.path1() == f );
}
// PR libstdc++/101510 create_directory on an existing symlink to a directory
fs::create_directory(p/"dir");
auto link = p/"link";
fs::create_directory_symlink("dir", link);
ec = bad_ec;
b = fs::create_directory(link, ec);
VERIFY( !b );
VERIFY( !ec );
b = fs::create_directory(link);
VERIFY( !b );
remove_all(p, ec);
}

View File

@ -46,12 +46,40 @@ test01()
VERIFY( exists(p) );
// Test existing path (libstdc++/71036).
ec = make_error_code(std::errc::invalid_argument);
b = create_directory(p, ec);
VERIFY( !ec );
VERIFY( !b );
b = create_directory(p);
VERIFY( !b );
auto f = p/"file";
std::ofstream{f} << "create file";
b = create_directory(f, ec);
VERIFY( ec == std::errc::file_exists );
VERIFY( !b );
try
{
create_directory(f);
VERIFY( false );
}
catch (const fs::filesystem_error& e)
{
VERIFY( e.code() == std::errc::file_exists );
VERIFY( e.path1() == f );
}
// PR libstdc++/101510 create_directory on an existing symlink to a directory
fs::create_directory(p/"dir");
auto link = p/"link";
fs::create_directory_symlink("dir", link);
ec = make_error_code(std::errc::invalid_argument);
b = fs::create_directory(link, ec);
VERIFY( !b );
VERIFY( !ec );
b = fs::create_directory(link);
VERIFY( !b );
remove_all(p, ec);
}