Skip to content

Commit

Permalink
fs: remove basename in favor of std::filesystem
Browse files Browse the repository at this point in the history
PR-URL: nodejs#53062
Reviewed-By: Daniel Lemire <daniel@lemire.me>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Richard Lau <rlau@redhat.com>
  • Loading branch information
anonrig authored and SophonieBouye committed Jun 20, 2024
1 parent df5b0a0 commit b23c493
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 28 deletions.
4 changes: 3 additions & 1 deletion src/node_errors.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <cerrno>
#include <cstdarg>
#include <filesystem>
#include <sstream>

#include "debug_utils-inl.h"
Expand Down Expand Up @@ -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());
}
}

Expand Down
23 changes: 0 additions & 23 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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> value) {
return IsSafeJsInt(value) ? value.As<Integer>()->Value() : -1;
}
Expand Down
4 changes: 0 additions & 4 deletions src/node_internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -415,10 +415,6 @@ BaseObjectPtr<AsyncWrap> 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);
Expand Down

0 comments on commit b23c493

Please sign in to comment.