From b23c49308b450624587a6db2e5e0a2097655d409 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Tue, 21 May 2024 21:20:41 -0400 Subject: [PATCH] fs: remove basename in favor of std::filesystem MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/53062 Reviewed-By: Daniel Lemire Reviewed-By: Rafael Gonzaga Reviewed-By: Mohammed Keyvanzadeh Reviewed-By: Stephen Belanger Reviewed-By: Tobias Nießen Reviewed-By: Richard Lau --- src/node_errors.cc | 4 +++- src/node_file.cc | 23 ----------------------- src/node_internals.h | 4 ---- 3 files changed, 3 insertions(+), 28 deletions(-) diff --git a/src/node_errors.cc b/src/node_errors.cc index d2053417c8eb9e..b055c1e70dbf60 100644 --- a/src/node_errors.cc +++ b/src/node_errors.cc @@ -1,5 +1,6 @@ #include #include +#include #include #include "debug_utils-inl.h" @@ -538,10 +539,11 @@ static void ReportFatalException(Environment* env, std::string argv0; if (!env->argv().empty()) argv0 = env->argv()[0]; if (argv0.empty()) argv0 = "node"; + auto filesystem_path = std::filesystem::path(argv0).replace_extension(); FPrintF(stderr, "(Use `%s --trace-uncaught ...` to show where the exception " "was thrown)\n", - fs::Basename(argv0, ".exe")); + filesystem_path.filename().string()); } } diff --git a/src/node_file.cc b/src/node_file.cc index 8194a71f7d1369..7fd63b3a1c69de 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -82,29 +82,6 @@ constexpr char kPathSeparator = '/'; const char* const kPathSeparator = "\\/"; #endif -std::string Basename(const std::string& str, const std::string& extension) { - // Remove everything leading up to and including the final path separator. - std::string::size_type pos = str.find_last_of(kPathSeparator); - - // Starting index for the resulting string - std::size_t start_pos = 0; - // String size to return - std::size_t str_size = str.size(); - if (pos != std::string::npos) { - start_pos = pos + 1; - str_size -= start_pos; - } - - // Strip away the extension, if any. - if (str_size >= extension.size() && - str.compare(str.size() - extension.size(), - extension.size(), extension) == 0) { - str_size -= extension.size(); - } - - return str.substr(start_pos, str_size); -} - inline int64_t GetOffset(Local value) { return IsSafeJsInt(value) ? value.As()->Value() : -1; } diff --git a/src/node_internals.h b/src/node_internals.h index 1c07810667ca6e..7bd7f584d505d5 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -415,10 +415,6 @@ BaseObjectPtr CreateHeapSnapshotStream( Environment* env, HeapSnapshotPointer&& snapshot); } // namespace heap -namespace fs { -std::string Basename(const std::string& str, const std::string& extension); -} // namespace fs - node_module napi_module_to_node_module(const napi_module* mod); std::ostream& operator<<(std::ostream& output, const SnapshotFlags& flags);