From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 46A8D3858001; Wed, 10 Mar 2021 23:04:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 46A8D3858001 From: "ssh at pobox dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/99533] New: "operation not permitted" error on recursive_directory_iterator despite skip_permission_denied Date: Wed, 10 Mar 2021 23:04:55 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 10.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: ssh at pobox dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Mar 2021 23:04:55 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99533 Bug ID: 99533 Summary: "operation not permitted" error on recursive_directory_iterator despite skip_permission_denied Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: ssh at pobox dot com Target Milestone: --- On POSIX filesystem backend type systems the std::filesystem::recursive_directory_iterator throws a filesystem_error exception with "operation not permitted" when the opendir/readdir call retu= rns EPERM instead of EACCES even if std::filesystem::directory_options::skip_permission_denied is set. Given the following code: #include #include int main(int argc, char* argv[]) { fs::path dir{"."}; if(argc =3D=3D 2) { dir =3D fs::u8path(argv[1]); } int totalDirs =3D 0; int totalFiles =3D 0; try { for(const auto& de : fs::recursive_directory_iterator(dir, fs::directory_options::skip_permission_denied)) { if(de.is_regular_file()) { ++totalFiles; } else if(de.is_directory()) { ++totalDirs; } } } catch(fs::filesystem_error fe) { std::cerr << "Error: " << fe.what() << std::endl; exit(1); } std::cout << totalFiles << " files in " << totalDirs << " directories" = << std::endl; return 0; } This fails for example on macOS when called on the user home directory with: Error: filesystem error: cannot increment recursive directory iterator: Operation not permitted This is due to System Integrity Protection (since macOS 10.14) on the "/Users//Library/Application Support/MobileSync" folder leading to EP= ERM. On Linux, called with / it stops when hitting for example a "/proc/1/task/1/cwd", resulting in EPERM too. I don't have examples from other POSIX systems, but I would say handling on= ly EACCES for the skip_permission_denied option is not enough.=