Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: move FromNamespacedPath to path.cc #53540

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -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;
Expand Down
13 changes: 0 additions & 13 deletions src/node_url.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
H4ad marked this conversation as resolved.
Show resolved Hide resolved
*path = path->substr(8);
path->insert(0, "\\\\");
} else if (path->compare(0, 4, "\\\\?\\", 4) == 0) {
*path = path->substr(4);
}
#endif
}

} // namespace url

} // namespace node
Expand Down
1 change: 0 additions & 1 deletion src/node_url.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 13 additions & 0 deletions src/path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions src/path.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ constexpr bool IsWindowsDeviceRoot(const char c) noexcept;
#endif // _WIN32

void ToNamespacedPath(Environment* env, BufferValue* path);
void FromNamespacedPath(std::string* path);
anonrig marked this conversation as resolved.
Show resolved Hide resolved

} // namespace node

Expand Down
Loading