Skip to content

Commit 7940db7

Browse files
anonrigtargos
authored andcommitted
fs: remove basename in favor of std::filesystem
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]>
1 parent ec44965 commit 7940db7

File tree

3 files changed

+3
-28
lines changed

3 files changed

+3
-28
lines changed

Diff for: src/node_errors.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <cerrno>
22
#include <cstdarg>
3+
#include <filesystem>
34
#include <sstream>
45

56
#include "debug_utils-inl.h"
@@ -538,10 +539,11 @@ static void ReportFatalException(Environment* env,
538539
std::string argv0;
539540
if (!env->argv().empty()) argv0 = env->argv()[0];
540541
if (argv0.empty()) argv0 = "node";
542+
auto filesystem_path = std::filesystem::path(argv0).replace_extension();
541543
FPrintF(stderr,
542544
"(Use `%s --trace-uncaught ...` to show where the exception "
543545
"was thrown)\n",
544-
fs::Basename(argv0, ".exe"));
546+
filesystem_path.filename().string());
545547
}
546548
}
547549

Diff for: src/node_file.cc

-23
Original file line numberDiff line numberDiff line change
@@ -82,29 +82,6 @@ constexpr char kPathSeparator = '/';
8282
const char* const kPathSeparator = "\\/";
8383
#endif
8484

85-
std::string Basename(const std::string& str, const std::string& extension) {
86-
// Remove everything leading up to and including the final path separator.
87-
std::string::size_type pos = str.find_last_of(kPathSeparator);
88-
89-
// Starting index for the resulting string
90-
std::size_t start_pos = 0;
91-
// String size to return
92-
std::size_t str_size = str.size();
93-
if (pos != std::string::npos) {
94-
start_pos = pos + 1;
95-
str_size -= start_pos;
96-
}
97-
98-
// Strip away the extension, if any.
99-
if (str_size >= extension.size() &&
100-
str.compare(str.size() - extension.size(),
101-
extension.size(), extension) == 0) {
102-
str_size -= extension.size();
103-
}
104-
105-
return str.substr(start_pos, str_size);
106-
}
107-
10885
inline int64_t GetOffset(Local<Value> value) {
10986
return IsSafeJsInt(value) ? value.As<Integer>()->Value() : -1;
11087
}

Diff for: src/node_internals.h

-4
Original file line numberDiff line numberDiff line change
@@ -415,10 +415,6 @@ BaseObjectPtr<AsyncWrap> CreateHeapSnapshotStream(
415415
Environment* env, HeapSnapshotPointer&& snapshot);
416416
} // namespace heap
417417

418-
namespace fs {
419-
std::string Basename(const std::string& str, const std::string& extension);
420-
} // namespace fs
421-
422418
node_module napi_module_to_node_module(const napi_module* mod);
423419

424420
std::ostream& operator<<(std::ostream& output, const SnapshotFlags& flags);

0 commit comments

Comments
 (0)