public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc r9-9375] libstdc++: Handle EPERM for filesystem access errors on MacOS [PR 99537]
Date: Tue, 20 Apr 2021 18:52:49 +0000 (GMT)	[thread overview]
Message-ID: <20210420185249.E74F5388A437@sourceware.org> (raw)

https://gcc.gnu.org/g:b06bc096c4da89d8880f86fb0d9627168f22c50d

commit r9-9375-gb06bc096c4da89d8880f86fb0d9627168f22c50d
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Mar 11 16:43:51 2021 +0000

    libstdc++: Handle EPERM for filesystem access errors on MacOS [PR 99537]
    
    Contrary to what POSIX says, some directory operations on MacOS can fail
    with EPERM instead of EACCES, so we need to handle both.
    
    libstdc++-v3/ChangeLog:
    
            PR libstdc++/99533
            * src/c++17/fs_dir.cc (recursive_directory_iterator): Use new
            helper function to check for permission denied errors.
            * src/filesystem/dir.cc (recursive_directory_iterator):
            Likewise.
            * src/filesystem/dir-common.h (is_permission_denied_error): New
            helper function.
    
    (cherry picked from commit 8cfb387388a90730ab36ac24d9049677db633a11)

Diff:
---
 libstdc++-v3/src/c++17/fs_dir.cc         |  2 +-
 libstdc++-v3/src/filesystem/dir-common.h | 12 ++++++++++++
 libstdc++-v3/src/filesystem/dir.cc       |  2 +-
 3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/src/c++17/fs_dir.cc b/libstdc++-v3/src/c++17/fs_dir.cc
index bcbcd7ba6b3..b4d6862fe34 100644
--- a/libstdc++-v3/src/c++17/fs_dir.cc
+++ b/libstdc++-v3/src/c++17/fs_dir.cc
@@ -211,7 +211,7 @@ recursive_directory_iterator(const path& p, directory_options options,
   else
     {
       const int err = errno;
-      if (err == EACCES
+      if (fs::is_permission_denied_error(err)
 	  && is_set(options, fs::directory_options::skip_permission_denied))
 	{
 	  if (ecptr)
diff --git a/libstdc++-v3/src/filesystem/dir-common.h b/libstdc++-v3/src/filesystem/dir-common.h
index 6ec798c9aa0..97ad70f834e 100644
--- a/libstdc++-v3/src/filesystem/dir-common.h
+++ b/libstdc++-v3/src/filesystem/dir-common.h
@@ -141,6 +141,18 @@ struct _Dir_base
   posix::DIR*	dirp;
 };
 
+inline bool
+is_permission_denied_error(int e)
+{
+  if (e == EACCES)
+    return true;
+#ifdef __APPLE__
+  if (e == EPERM) // See PR 99533
+    return true;
+#endif
+  return false;
+}
+
 } // namespace filesystem
 
 // BEGIN/END macros must be defined before including this file.
diff --git a/libstdc++-v3/src/filesystem/dir.cc b/libstdc++-v3/src/filesystem/dir.cc
index d7d8eb74066..b3978f82b51 100644
--- a/libstdc++-v3/src/filesystem/dir.cc
+++ b/libstdc++-v3/src/filesystem/dir.cc
@@ -202,7 +202,7 @@ recursive_directory_iterator(const path& p, directory_options options,
   else
     {
       const int err = errno;
-      if (err == EACCES
+      if (std::filesystem::is_permission_denied_error(err)
 	  && is_set(options, fs::directory_options::skip_permission_denied))
 	{
 	  if (ecptr)


                 reply	other threads:[~2021-04-20 18:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210420185249.E74F5388A437@sourceware.org \
    --to=redi@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).