From: Lancelot SIX <lancelot.six@amd.com>
To: <gdb-patches@sourceware.org>
Cc: <lsix@lancelotsix.com>, Lancelot SIX <lancelot.six@amd.com>
Subject: [PATCH] gdb/compile: Use std::filesystem::remove_all in cleanup
Date: Sun, 3 Mar 2024 16:47:56 +0000 [thread overview]
Message-ID: <20240303164756.870514-1-lancelot.six@amd.com> (raw)
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 ...");`.
This patch implements this.
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.
Tested on x86_64-linux.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31420
Change-Id: If5668bf3e15e66c020e5c3b4fa999f861690e4cf
---
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 27cff2553ee..45452f19abb 100644
--- a/gdb/compile/compile.c
+++ b/gdb/compile/compile.c
@@ -40,7 +40,9 @@
#include "osabi.h"
#include "gdbsupport/gdb_wait.h"
#include "valprint.h"
+#include <filesystem>
#include <optional>
+#include <system_error>
#include "gdbsupport/gdb_unlinker.h"
#include "gdbsupport/pathstuff.h"
#include "gdbsupport/scoped_ignore_signal.h"
@@ -450,15 +452,11 @@ get_compile_file_tempdir (void)
tempdir_name = xstrdup (tempdir_name);
add_final_cleanup ([] ()
{
- char *zap;
- int wstat;
-
- gdb_assert (startswith (tempdir_name, TMP_PREFIX));
- zap = concat ("rm -rf ", tempdir_name, (char *) NULL);
- wstat = system (zap);
- if (wstat == -1 || !WIFEXITED (wstat) || WEXITSTATUS (wstat) != 0)
- warning (_("Could not remove temporary directory %s"), tempdir_name);
- XDELETEVEC (zap);
+ std::error_code error;
+ if (std::filesystem::remove_all (tempdir_name, error)
+ == static_cast<std::uintmax_t> (-1))
+ warning (_("Could not remove temporary directory %s (%s)"),
+ tempdir_name, error.message ().c_str ());
});
return tempdir_name;
}
base-commit: 90f8d97c8efa75f7f019b868eca9c626bc35203d
--
2.34.1
next reply other threads:[~2024-03-03 16:48 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-03 16:47 Lancelot SIX [this message]
2024-03-08 16:27 ` Tom Tromey
2024-04-03 12:56 ` Lancelot SIX
2024-04-03 14:37 ` Tom de Vries
2024-04-03 14:47 ` Lancelot SIX
2024-04-03 14:51 ` Tom de Vries
2024-04-03 17:08 ` Andrew Pinski
2024-04-04 7:40 ` Lancelot SIX
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=20240303164756.870514-1-lancelot.six@amd.com \
--to=lancelot.six@amd.com \
--cc=gdb-patches@sourceware.org \
--cc=lsix@lancelotsix.com \
/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).