Skip to content

Commit 9a2cd4c

Browse files
committed
fs,url: move FromNamespacedPath to node_url
1 parent db309a6 commit 9a2cd4c

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

src/node_file.cc

+4-17
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(),
@@ -1811,7 +1798,7 @@ static void MKDir(const FunctionCallbackInfo<Value>& args) {
18111798
!req_wrap_sync.continuation_data()->first_path().empty()) {
18121799
Local<Value> error;
18131800
std::string first_path(req_wrap_sync.continuation_data()->first_path());
1814-
FromNamespacedPath(&first_path);
1801+
node::url::FromNamespacedPath(&first_path);
18151802
MaybeLocal<Value> path = StringBytes::Encode(env->isolate(),
18161803
first_path.c_str(),
18171804
UTF8, &error);
@@ -2932,7 +2919,7 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
29322919
return;
29332920
}
29342921

2935-
FromNamespacedPath(&initial_file_path.value());
2922+
node::url::FromNamespacedPath(&initial_file_path.value());
29362923

29372924
for (int i = 0; i < legacy_main_extensions_with_main_end; i++) {
29382925
file_path = *initial_file_path + std::string(legacy_main_extensions[i]);
@@ -2967,7 +2954,7 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
29672954
return;
29682955
}
29692956

2970-
FromNamespacedPath(&initial_file_path.value());
2957+
node::url::FromNamespacedPath(&initial_file_path.value());
29712958

29722959
for (int i = legacy_main_extensions_with_main_end;
29732960
i < legacy_main_extensions_package_fallback_end;

src/node_url.cc

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

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

532545
} // 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)