diff options
author | redi <redi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2016-10-22 11:42:16 +0000 |
---|---|---|
committer | redi <redi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2016-10-22 11:42:16 +0000 |
commit | 3bf511da48bad4d5e1b9ea16f15ff376720a0143 (patch) | |
tree | 918bd00e2ea5664a78f8c0c01380db76dcf2c198 /libstdc++-v3/src/filesystem/ops.cc | |
parent | 14326a2259dd4bbbf70968d866bfd01db85945c7 (diff) |
Ignore perms::symlink_nofollow on non-symlinks
* src/filesystem/ops.cc (permissions(const path&, perms, error_code&)):
Ignore symlink_nofollow flag if file is not a symlink.
* testsuite/experimental/filesystem/operations/permissions.cc: Test
symlink_nofollow on non-symlinks.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@241438 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/src/filesystem/ops.cc')
-rw-r--r-- | libstdc++-v3/src/filesystem/ops.cc | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/libstdc++-v3/src/filesystem/ops.cc b/libstdc++-v3/src/filesystem/ops.cc index 68343a938249..2286e2201f4f 100644 --- a/libstdc++-v3/src/filesystem/ops.cc +++ b/libstdc++-v3/src/filesystem/ops.cc @@ -1097,7 +1097,8 @@ fs::permissions(const path& p, perms prms) _GLIBCXX_THROW_OR_ABORT(filesystem_error("cannot set permissions", p, ec)); } -void fs::permissions(const path& p, perms prms, error_code& ec) noexcept +void +fs::permissions(const path& p, perms prms, error_code& ec) noexcept { const bool add = is_set(prms, perms::add_perms); const bool remove = is_set(prms, perms::remove_perms); @@ -1110,27 +1111,33 @@ void fs::permissions(const path& p, perms prms, error_code& ec) noexcept prms &= perms::mask; - if (add || remove) + file_status st; + if (add || remove || nofollow) { - auto st = nofollow ? symlink_status(p, ec) : status(p, ec); + st = nofollow ? symlink_status(p, ec) : status(p, ec); if (ec) return; auto curr = st.permissions(); if (add) prms |= curr; - else + else if (remove) prms = curr & ~prms; } + int err = 0; #if _GLIBCXX_USE_FCHMODAT - const int flag = nofollow ? AT_SYMLINK_NOFOLLOW : 0; + const int flag = (nofollow && is_symlink(st)) ? AT_SYMLINK_NOFOLLOW : 0; if (::fchmodat(AT_FDCWD, p.c_str(), static_cast<mode_t>(prms), flag)) + err = errno; #else - if (nofollow) + if (nofollow && is_symlink(st)) ec = std::make_error_code(std::errc::operation_not_supported); else if (::chmod(p.c_str(), static_cast<mode_t>(prms))) + err = errno; #endif - ec.assign(errno, std::generic_category()); + + if (err) + ec.assign(err, std::generic_category()); else ec.clear(); } |