From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E919D3861C7D; Tue, 20 Jul 2021 11:46:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E919D3861C7D From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/101510] std::filesystem::create_directory on an existing symlink to a directory Date: Tue, 20 Jul 2021 11:46:32 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 11.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: WAITING X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: redi at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: 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: Tue, 20 Jul 2021 11:46:33 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D101510 --- Comment #2 from Jonathan Wakely --- (In reply to Madhu from comment #0) > cppreference.com states >=20 > ```=09 > bool create_directory( const std::filesystem::path& p ); >=20 > Creates the directory p as if by POSIX mkdir() with a second argument of > static_cast(std::filesystem::perms::all) (the parent directory must > already exist). If the function fails because p resolves to an existing > directory, no error is reported. Otherwise on failure an error is reporte= d. > ``` >=20 > This should accomodate situations when `p' resolves to an existing direct= ory > when `p' it is a symbolic link. >=20 > However create_directory(p) fails when p is a symbolic link which points > to an existing directory. >=20 > The standard usage pattern is to call mkdir(p) - and if it fails on EEXIST > to stat(2) p - following symlinks, and check if is a directory. The patte= rn > is used to ensure that `p' can be treated as a directory for further > operations and this includes p being a symbolic link to a directory) You can do this with create_directory. If create_directory(p) doesn't throw= an exception, then is_directory(p) is true. Or without exceptions: std::error_code ec; create_directory(p, ec); if (!ec) { // p resolves to a directory }=