Skip to content

Commit

Permalink
src: move FromNamespacedPath to path.cc
Browse files Browse the repository at this point in the history
PR-URL: #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>
  • Loading branch information
anonrig authored and aduh95 committed Jul 16, 2024
1 parent 82d88a8 commit cc1f497
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
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) {
*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);

} // namespace node

Expand Down

0 comments on commit cc1f497

Please sign in to comment.