summaryrefslogtreecommitdiffstats
path: root/libcxx/src
diff options
context:
space:
mode:
authorEric Fiselier <eric@efcs.ca>2016-06-21 22:42:42 +0000
committerEric Fiselier <eric@efcs.ca>2016-06-21 22:42:42 +0000
commit44e2ebadb2582936e4d6608e50ef234e22c89f87 (patch)
tree55f5144a3abfbbef93c61a9757bf8084fdc3a747 /libcxx/src
parent25da86a5dbb88f4916441d971eb44e21e2613d5c (diff)
downloadbcm5719-llvm-44e2ebadb2582936e4d6608e50ef234e22c89f87.tar.gz
bcm5719-llvm-44e2ebadb2582936e4d6608e50ef234e22c89f87.zip
Implement LWG issue 2720. Replace perms::resolve_symlinks with perms::symlink_nofollow.
This changes how filesystem::permissions(p, perms) handles symlinks. Previously symlinks were not resolved by default instead only getting resolved when "perms::resolve_symlinks" was used. After this change symlinks are resolved by default and perms::symlink_nofollow must be given to change this. This issue has not yet been moved to Ready status, and I will revert if it doesn't get moved at the current meeting. However I feel confident that it will and it's nice to have implementations when moving issues. llvm-svn: 273328
Diffstat (limited to 'libcxx/src')
-rw-r--r--libcxx/src/experimental/filesystem/operations.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/libcxx/src/experimental/filesystem/operations.cpp b/libcxx/src/experimental/filesystem/operations.cpp
index 9bfba71fce7..4e7b233e6ce 100644
--- a/libcxx/src/experimental/filesystem/operations.cpp
+++ b/libcxx/src/experimental/filesystem/operations.cpp
@@ -594,7 +594,7 @@ void __last_write_time(const path& p, file_time_type new_time,
void __permissions(const path& p, perms prms, std::error_code *ec)
{
- const bool resolve_symlinks = bool(perms::resolve_symlinks & prms);
+ const bool resolve_symlinks = !bool(perms::symlink_nofollow & prms);
const bool add_perms = bool(perms::add_perms & prms);
const bool remove_perms = bool(perms::remove_perms & prms);
@@ -605,6 +605,8 @@ void __permissions(const path& p, perms prms, std::error_code *ec)
file_status st = detail::posix_lstat(p, &m_ec);
if (m_ec) return set_or_throw(m_ec, ec, "permissions", p);
+ // AT_SYMLINK_NOFOLLOW can only be used on symlinks, using it on a regular
+ // file will cause fchmodat to report an error on some systems.
const bool set_sym_perms = is_symlink(st) && !resolve_symlinks;
if ((resolve_symlinks && is_symlink(st)) && (add_perms || remove_perms)) {
@@ -622,14 +624,16 @@ void __permissions(const path& p, perms prms, std::error_code *ec)
# if defined(AT_SYMLINK_NOFOLLOW) && defined(AT_FDCWD)
const int flags = set_sym_perms ? AT_SYMLINK_NOFOLLOW : 0;
if (::fchmodat(AT_FDCWD, p.c_str(), real_perms, flags) == -1) {
+ return set_or_throw(ec, "permissions", p);
+ }
# else
if (set_sym_perms)
return set_or_throw(make_error_code(errc::operation_not_supported),
ec, "permissions", p);
if (::chmod(p.c_str(), real_perms) == -1) {
-# endif
return set_or_throw(ec, "permissions", p);
}
+# endif
if (ec) ec->clear();
}
OpenPOWER on IntegriCloud