From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7833) id 1C2F03858401; Wed, 3 Apr 2024 12:53:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1C2F03858401 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1712148839; bh=rb8+6y1JXupH+elE3dVbqkQFmbae6UkgADoX3LCC0eQ=; h=From:To:Subject:Date:From; b=vjdf1pK8Rs8TbQRWBkjSXvg8CICCpwYNQrAy1nrUgqhxQwbo3GIGP20h49sW+yn+G tc1UASMmzWQbiFp2neRitJm1ovJOfYagXth2a8xLAArvlLYHB7tHfEG780ZbkTKsRA lQeis3a5xC+Ee+78YEMBHhB2RU9h4VN45BF52yjI= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Lancelot SIX To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb/compile: Use std::filesystem::remove_all in cleanup X-Act-Checkin: binutils-gdb X-Git-Author: Lancelot SIX X-Git-Refname: refs/heads/master X-Git-Oldrev: e73b04d26504214f52a3b87f51917d26aba8e82c X-Git-Newrev: 7bba0ad08576309763e3f41193eaa93025e10b8b Message-Id: <20240403125359.1C2F03858401@sourceware.org> Date: Wed, 3 Apr 2024 12:53:59 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D7bba0ad08576= 309763e3f41193eaa93025e10b8b commit 7bba0ad08576309763e3f41193eaa93025e10b8b Author: Lancelot SIX Date: Sun Mar 3 16:47:56 2024 +0000 gdb/compile: Use std::filesystem::remove_all in cleanup =20 In a previous review, I noticed that some code in gdb/compile/compile.c could use c++17's `std::filesystem::remove_all` instead of using some `system ("rm -rf ...");`. =20 This patch implements this. =20 Note that I use the noexcept overload of std::filesystem::remove_all and explicitly check for an error code. This means that this code called during the cleanup procedure cannot throw, and does not risk preventing other cleanup functions to be called. =20 Tested on x86_64-linux. =20 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=3D31420 Change-Id: If5668bf3e15e66c020e5c3b4fa999f861690e4cf Approved-By: Tom Tromey Diff: --- gdb/compile/compile.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c index 2d97a1b2005..bff69a5092d 100644 --- a/gdb/compile/compile.c +++ b/gdb/compile/compile.c @@ -39,7 +39,9 @@ #include "osabi.h" #include "gdbsupport/gdb_wait.h" #include "valprint.h" +#include #include +#include #include "gdbsupport/gdb_unlinker.h" #include "gdbsupport/pathstuff.h" #include "gdbsupport/scoped_ignore_signal.h" @@ -449,15 +451,11 @@ get_compile_file_tempdir (void) tempdir_name =3D xstrdup (tempdir_name); add_final_cleanup ([] () { - char *zap; - int wstat; - - gdb_assert (startswith (tempdir_name, TMP_PREFIX)); - zap =3D concat ("rm -rf ", tempdir_name, (char *) NULL); - wstat =3D system (zap); - if (wstat =3D=3D -1 || !WIFEXITED (wstat) || WEXITSTATUS (wstat) != =3D 0) - warning (_("Could not remove temporary directory %s"), tempdir_name); - XDELETEVEC (zap); + std::error_code error; + if (std::filesystem::remove_all (tempdir_name, error) + =3D=3D static_cast (-1)) + warning (_("Could not remove temporary directory %s (%s)"), + tempdir_name, error.message ().c_str ()); }); return tempdir_name; }