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: #53062
Reviewed-By: Daniel Lemire <[email protected]>
Reviewed-By: Rafael Gonzaga <[email protected]>
Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
Reviewed-By: Stephen Belanger <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
  • Loading branch information
anonrig authored and targos committed Jun 1, 2024
1 parent ec44965 commit 7940db7
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 7940db7

Please sign in to comment.