mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
src: move FromNamespacedPath to path.cc
PR-URL: https://github.com/nodejs/node/pull/53540 Reviewed-By: Daniel Lemire <daniel@lemire.me> Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br> Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
This commit is contained in:
@@ -3098,7 +3098,7 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
|
||||
return;
|
||||
}
|
||||
|
||||
node::url::FromNamespacedPath(&initial_file_path.value());
|
||||
FromNamespacedPath(&initial_file_path.value());
|
||||
|
||||
for (int i = 0; i < legacy_main_extensions_with_main_end; i++) {
|
||||
file_path = *initial_file_path + std::string(legacy_main_extensions[i]);
|
||||
@@ -3133,7 +3133,7 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
|
||||
return;
|
||||
}
|
||||
|
||||
node::url::FromNamespacedPath(&initial_file_path.value());
|
||||
FromNamespacedPath(&initial_file_path.value());
|
||||
|
||||
for (int i = legacy_main_extensions_with_main_end;
|
||||
i < legacy_main_extensions_package_fallback_end;
|
||||
|
||||
@@ -544,19 +544,6 @@ std::optional<std::string> FileURLToPath(Environment* env,
|
||||
#endif // _WIN32
|
||||
}
|
||||
|
||||
// Reverse the logic applied by path.toNamespacedPath() to create a
|
||||
// namespace-prefixed path.
|
||||
void FromNamespacedPath(std::string* path) {
|
||||
#ifdef _WIN32
|
||||
if (path->compare(0, 8, "\\\\?\\UNC\\", 8) == 0) {
|
||||
*path = path->substr(8);
|
||||
path->insert(0, "\\\\");
|
||||
} else if (path->compare(0, 4, "\\\\?\\", 4) == 0) {
|
||||
*path = path->substr(4);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace url
|
||||
|
||||
} // namespace node
|
||||
|
||||
@@ -85,7 +85,6 @@ void ThrowInvalidURL(Environment* env,
|
||||
std::string FromFilePath(std::string_view file_path);
|
||||
std::optional<std::string> FileURLToPath(Environment* env,
|
||||
const ada::url_aggregator& file_url);
|
||||
void FromNamespacedPath(std::string* path);
|
||||
|
||||
} // namespace url
|
||||
|
||||
|
||||
13
src/path.cc
13
src/path.cc
@@ -314,4 +314,17 @@ void ToNamespacedPath(Environment* env, BufferValue* path) {
|
||||
#endif
|
||||
}
|
||||
|
||||
// Reverse the logic applied by path.toNamespacedPath() to create a
|
||||
// namespace-prefixed path.
|
||||
void FromNamespacedPath(std::string* path) {
|
||||
#ifdef _WIN32
|
||||
if (path->starts_with("\\\\?\\UNC\\")) {
|
||||
*path = path->substr(8);
|
||||
path->insert(0, "\\\\");
|
||||
} else if (path->starts_with("\\\\?\\")) {
|
||||
*path = path->substr(4);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace node
|
||||
|
||||
@@ -24,6 +24,7 @@ constexpr bool IsWindowsDeviceRoot(const char c) noexcept;
|
||||
#endif // _WIN32
|
||||
|
||||
void ToNamespacedPath(Environment* env, BufferValue* path);
|
||||
void FromNamespacedPath(std::string* path);
|
||||
|
||||
} // namespace node
|
||||
|
||||
|
||||
Reference in New Issue
Block a user