Skip to content

Commit a8cbc30

Browse files
committedOct 9, 2023
fs,url: move FromNamespacedPath to node_url
1 parent 5f628fe commit a8cbc30

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed
 

‎src/node_file.cc

+5-19
Original file line numberDiff line numberDiff line change
@@ -842,19 +842,6 @@ void AfterOpenFileHandle(uv_fs_t* req) {
842842
}
843843
}
844844

845-
// Reverse the logic applied by path.toNamespacedPath() to create a
846-
// namespace-prefixed path.
847-
void FromNamespacedPath(std::string* path) {
848-
#ifdef _WIN32
849-
if (path->compare(0, 8, "\\\\?\\UNC\\", 8) == 0) {
850-
*path = path->substr(8);
851-
path->insert(0, "\\\\");
852-
} else if (path->compare(0, 4, "\\\\?\\", 4) == 0) {
853-
*path = path->substr(4);
854-
}
855-
#endif
856-
}
857-
858845
void AfterMkdirp(uv_fs_t* req) {
859846
FSReqBase* req_wrap = FSReqBase::from_req(req);
860847
FSReqAfterScope after(req_wrap, req);
@@ -864,7 +851,7 @@ void AfterMkdirp(uv_fs_t* req) {
864851
std::string first_path(req_wrap->continuation_data()->first_path());
865852
if (first_path.empty())
866853
return req_wrap->Resolve(Undefined(req_wrap->env()->isolate()));
867-
FromNamespacedPath(&first_path);
854+
node::url::FromNamespacedPath(&first_path);
868855
Local<Value> path;
869856
Local<Value> error;
870857
if (!StringBytes::Encode(req_wrap->env()->isolate(), first_path.c_str(),
@@ -1813,7 +1800,7 @@ static void MKDir(const FunctionCallbackInfo<Value>& args) {
18131800
!req_wrap_sync.continuation_data()->first_path().empty()) {
18141801
Local<Value> error;
18151802
std::string first_path(req_wrap_sync.continuation_data()->first_path());
1816-
FromNamespacedPath(&first_path);
1803+
node::url::FromNamespacedPath(&first_path);
18171804
MaybeLocal<Value> path = StringBytes::Encode(env->isolate(),
18181805
first_path.c_str(),
18191806
UTF8, &error);
@@ -2915,8 +2902,7 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
29152902
std::string file_path;
29162903

29172904
if (args.Length() >= 2 && args[1]->IsString()) {
2918-
auto package_config_main =
2919-
Utf8Value(isolate, args[1]).ToString();
2905+
auto package_config_main = Utf8Value(isolate, args[1]).ToString();
29202906

29212907
file_path_url = ada::parse<ada::url_aggregator>(
29222908
std::string("./") + package_config_main, &package_json_url.value());
@@ -2931,7 +2917,7 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
29312917
return;
29322918
}
29332919

2934-
FromNamespacedPath(&initial_file_path.value());
2920+
node::url::FromNamespacedPath(&initial_file_path.value());
29352921

29362922
for (int i = 0; i < legacy_main_extensions_with_main_end; i++) {
29372923
file_path = *initial_file_path + std::string(legacy_main_extensions[i]);
@@ -2966,7 +2952,7 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
29662952
return;
29672953
}
29682954

2969-
FromNamespacedPath(&initial_file_path.value());
2955+
node::url::FromNamespacedPath(&initial_file_path.value());
29702956

29712957
for (int i = legacy_main_extensions_with_main_end;
29722958
i < legacy_main_extensions_package_fallback_end;

‎src/node_url.cc

+13
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,19 @@ std::optional<std::string> FileURLToPath(Environment* env,
525525
#endif // _WIN32
526526
}
527527

528+
// Reverse the logic applied by path.toNamespacedPath() to create a
529+
// namespace-prefixed path.
530+
void FromNamespacedPath(std::string* path) {
531+
#ifdef _WIN32
532+
if (path->compare(0, 8, "\\\\?\\UNC\\", 8) == 0) {
533+
*path = path->substr(8);
534+
path->insert(0, "\\\\");
535+
} else if (path->compare(0, 4, "\\\\?\\", 4) == 0) {
536+
*path = path->substr(4);
537+
}
538+
#endif
539+
}
540+
528541
} // namespace url
529542

530543
} // namespace node

‎src/node_url.h

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class BindingData : public SnapshotableObject {
8585
std::string FromFilePath(const std::string_view file_path);
8686
std::optional<std::string> FileURLToPath(Environment* env,
8787
const ada::url_aggregator& file_url);
88+
void FromNamespacedPath(std::string* path);
8889

8990
} // namespace url
9091

0 commit comments

Comments
 (0)