enum class file_type;
enum class perms;
+ enum class perm_options;
enum class copy_options;
enum class directory_options;
void last_write_time(const path& p, file_time_type new_time,
error_code& ec) _NOEXCEPT;
- void permissions(const path& p, perms prms);
- void permissions(const path& p, perms prms, error_code& ec) _NOEXCEPT;
+ void permissions(const path& p, perms prms,
+ perm_options opts=perm_options::replace);
+ void permissions(const path& p, perms prms, error_code& ec) noexcept;
+ void permissions(const path& p, perms prms, perm_options opts,
+ error_code& ec);
path read_symlink(const path& p);
path read_symlink(const path& p, error_code& ec);
sticky_bit = 01000,
mask = 07777,
unknown = 0xFFFF,
-
- add_perms = 0x10000,
- remove_perms = 0x20000,
- symlink_nofollow = 0x40000
};
_LIBCPP_INLINE_VISIBILITY
inline perms& operator^=(perms& _LHS, perms _RHS)
{ return _LHS = _LHS ^ _RHS; }
+enum class _LIBCPP_ENUM_VIS perm_options : unsigned char {
+ replace = 1,
+ add = 2,
+ remove = 4,
+ nofollow = 8
+};
+
+_LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_CONSTEXPR perm_options operator&(perm_options _LHS, perm_options _RHS)
+{ return static_cast<perm_options>(static_cast<unsigned>(_LHS) & static_cast<unsigned>(_RHS)); }
+
+_LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_CONSTEXPR perm_options operator|(perm_options _LHS, perm_options _RHS)
+{ return static_cast<perm_options>(static_cast<unsigned>(_LHS) | static_cast<unsigned>(_RHS)); }
+
+_LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_CONSTEXPR perm_options operator^(perm_options _LHS, perm_options _RHS)
+{ return static_cast<perm_options>(static_cast<unsigned>(_LHS) ^ static_cast<unsigned>(_RHS)); }
+
+_LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_CONSTEXPR perm_options operator~(perm_options _LHS)
+{ return static_cast<perm_options>(~static_cast<unsigned>(_LHS)); }
+
+_LIBCPP_INLINE_VISIBILITY
+inline perm_options& operator&=(perm_options& _LHS, perm_options _RHS)
+{ return _LHS = _LHS & _RHS; }
+
+_LIBCPP_INLINE_VISIBILITY
+inline perm_options& operator|=(perm_options& _LHS, perm_options _RHS)
+{ return _LHS = _LHS | _RHS; }
+
+_LIBCPP_INLINE_VISIBILITY
+inline perm_options& operator^=(perm_options& _LHS, perm_options _RHS)
+{ return _LHS = _LHS ^ _RHS; }
+
enum class _LIBCPP_ENUM_VIS copy_options : unsigned short
{
none = 0,
void __last_write_time(const path& p, file_time_type new_time,
error_code *ec=nullptr);
_LIBCPP_FUNC_VIS
-void __permissions(const path& p, perms prms, error_code *ec=nullptr);
+void __permissions(const path&, perms, perm_options, error_code* = nullptr);
_LIBCPP_FUNC_VIS
path __read_symlink(const path& p, error_code *ec=nullptr);
_LIBCPP_FUNC_VIS
}
inline _LIBCPP_INLINE_VISIBILITY
-void permissions(const path& __p, perms __prms) {
- __permissions(__p, __prms);
+void permissions(const path& __p, perms __prms,
+ perm_options __opts = perm_options::replace) {
+ __permissions(__p, __prms, __opts);
+}
+
+inline _LIBCPP_INLINE_VISIBILITY
+void permissions(const path& __p, perms __prms, error_code& __ec) _NOEXCEPT {
+ __permissions(__p, __prms, perm_options::replace, &__ec);
}
inline _LIBCPP_INLINE_VISIBILITY
-void permissions(const path& __p, perms __prms, error_code& __ec) {
- __permissions(__p, __prms, &__ec);
+void permissions(const path& __p, perms __prms, perm_options __opts,
+ error_code& __ec) {
+ __permissions(__p, __prms, __opts, &__ec);
}
inline _LIBCPP_INLINE_VISIBILITY
// <experimental/filesystem>
-// void permissions(const path& p, perms prms);
+// void permissions(const path& p, perms prms,
+// perm_options opts = perm_options::replace);
// void permissions(const path& p, perms prms, std::error_code& ec) noexcept;
+// void permissions(const path& p, perms prms, perm_options opts, std::error_code);
+
#include "filesystem_include.hpp"
TEST_CASE(test_signatures)
{
const path p; ((void)p);
- const perms opts{}; ((void)opts);
+ const perms pr{}; ((void)pr);
+ const perm_options opts{}; ((void)opts);
std::error_code ec; ((void)ec);
- ASSERT_NOT_NOEXCEPT(fs::permissions(p, opts));
- // Not noexcept because of narrow contract
- LIBCPP_ONLY(
- ASSERT_NOT_NOEXCEPT(fs::permissions(p, opts, ec)));
+ ASSERT_NOT_NOEXCEPT(fs::permissions(p, pr));
+ ASSERT_NOT_NOEXCEPT(fs::permissions(p, pr, opts));
+ ASSERT_NOEXCEPT(fs::permissions(p, pr, ec));
+ ASSERT_NOT_NOEXCEPT(fs::permissions(p, pr, opts, ec));
}
TEST_CASE(test_error_reporting)
{
- auto checkThrow = [](path const& f, fs::perms opts, const std::error_code& ec)
+ auto checkThrow = [](path const& f, fs::perms opts,
+ const std::error_code& ec)
{
#ifndef TEST_HAS_NO_EXCEPTIONS
try {
const path dne = env.make_env_path("dne");
const path dne_sym = env.create_symlink(dne, "dne_sym");
{ // !exists
- std::error_code ec;
+ std::error_code ec = GetTestEC();
fs::permissions(dne, fs::perms{}, ec);
TEST_REQUIRE(ec);
+ TEST_CHECK(ec != GetTestEC());
TEST_CHECK(checkThrow(dne, fs::perms{}, ec));
}
{
- std::error_code ec;
+ std::error_code ec = GetTestEC();
fs::permissions(dne_sym, fs::perms{}, ec);
TEST_REQUIRE(ec);
+ TEST_CHECK(ec != GetTestEC());
TEST_CHECK(checkThrow(dne_sym, fs::perms{}, ec));
}
}
const path dir = env.create_dir("dir1");
const path file_for_sym = env.create_file("file2", 42);
const path sym = env.create_symlink(file_for_sym, "sym");
- const perms AP = perms::add_perms;
- const perms RP = perms::remove_perms;
- const perms NF = perms::symlink_nofollow;
+ const perm_options AP = perm_options::add;
+ const perm_options RP = perm_options::remove;
+ const perm_options NF = perm_options::nofollow;
struct TestCase {
path p;
perms set_perms;
perms expected;
+ perm_options opts = perm_options::replace;
} cases[] = {
// test file
{file, perms::none, perms::none},
{file, perms::owner_all, perms::owner_all},
- {file, perms::group_all | AP, perms::owner_all | perms::group_all},
- {file, perms::group_all | RP, perms::owner_all},
+ {file, perms::group_all, perms::owner_all | perms::group_all, AP},
+ {file, perms::group_all, perms::owner_all, RP},
// test directory
{dir, perms::none, perms::none},
{dir, perms::owner_all, perms::owner_all},
- {dir, perms::group_all | AP, perms::owner_all | perms::group_all},
- {dir, perms::group_all | RP, perms::owner_all},
+ {dir, perms::group_all, perms::owner_all | perms::group_all, AP},
+ {dir, perms::group_all, perms::owner_all, RP},
// test symlink without symlink_nofollow
{sym, perms::none, perms::none},
{sym, perms::owner_all, perms::owner_all},
- {sym, perms::group_all | AP, perms::owner_all | perms::group_all},
- {sym, perms::group_all | RP , perms::owner_all},
+ {sym, perms::group_all, perms::owner_all | perms::group_all, AP},
+ {sym, perms::group_all, perms::owner_all, RP},
// test non-symlink with symlink_nofollow. The last test on file/dir
// will have set their permissions to perms::owner_all
- {file, perms::group_all | AP | NF, perms::owner_all | perms::group_all},
- {dir, perms::group_all | AP | NF, perms::owner_all | perms::group_all}
+ {file, perms::group_all, perms::owner_all | perms::group_all, AP | NF},
+ {dir, perms::group_all, perms::owner_all | perms::group_all, AP | NF}
};
for (auto const& TC : cases) {
TEST_CHECK(status(TC.p).permissions() != TC.expected);
- // Set the error code to ensure it's cleared.
- std::error_code ec = std::make_error_code(std::errc::bad_address);
- permissions(TC.p, TC.set_perms, ec);
- TEST_CHECK(!ec);
- auto pp = status(TC.p).permissions();
- TEST_CHECK(pp == TC.expected);
+ {
+ std::error_code ec = GetTestEC();
+ permissions(TC.p, TC.set_perms, TC.opts, ec);
+ TEST_CHECK(!ec);
+ auto pp = status(TC.p).permissions();
+ TEST_CHECK(pp == TC.expected);
+ }
+ if (TC.opts == perm_options::replace) {
+ std::error_code ec = GetTestEC();
+ permissions(TC.p, TC.set_perms, ec);
+ TEST_CHECK(!ec);
+ auto pp = status(TC.p).permissions();
+ TEST_CHECK(pp == TC.expected);
+ }
}
}
struct TestCase {
perms set_perms;
perms expected; // only expected on platform that support symlink perms.
+ perm_options opts = perm_options::replace;
} cases[] = {
{perms::owner_all, perms::owner_all},
- {perms::group_all | perms::add_perms, perms::owner_all | perms::group_all},
- {perms::owner_all | perms::remove_perms, perms::group_all},
+ {perms::group_all, perms::owner_all | perms::group_all, perm_options::add},
+ {perms::owner_all, perms::group_all, perm_options::remove},
};
for (auto const& TC : cases) {
#if defined(__APPLE__) || defined(__FreeBSD__)
const auto expected_link_perms = symlink_status(sym).permissions();
std::error_code expected_ec = std::make_error_code(std::errc::operation_not_supported);
#endif
- std::error_code ec = std::make_error_code(std::errc::bad_address);
- permissions(sym, TC.set_perms | perms::symlink_nofollow, ec);
+ std::error_code ec = GetTestEC();
+ permissions(sym, TC.set_perms, TC.opts | perm_options::nofollow, ec);
TEST_CHECK(ec == expected_ec);
TEST_CHECK(status(file).permissions() == file_perms);
TEST_CHECK(symlink_status(sym).permissions() == expected_link_perms);