Skip to content

Commit 868a464

Browse files
anonrigUlisesGascon
authored andcommitted
fs,url: move FromNamespacedPath to node_url
PR-URL: #50090 Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
1 parent de7fe08 commit 868a464

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(),
@@ -1825,7 +1812,7 @@ static void MKDir(const FunctionCallbackInfo<Value>& args) {
18251812
if (!req_wrap_sync.continuation_data()->first_path().empty()) {
18261813
Local<Value> error;
18271814
std::string first_path(req_wrap_sync.continuation_data()->first_path());
1828-
FromNamespacedPath(&first_path);
1815+
node::url::FromNamespacedPath(&first_path);
18291816
MaybeLocal<Value> path = StringBytes::Encode(env->isolate(),
18301817
first_path.c_str(),
18311818
UTF8, &error);
@@ -2935,7 +2922,7 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
29352922
return;
29362923
}
29372924

2938-
FromNamespacedPath(&initial_file_path.value());
2925+
node::url::FromNamespacedPath(&initial_file_path.value());
29392926

29402927
for (int i = 0; i < legacy_main_extensions_with_main_end; i++) {
29412928
file_path = *initial_file_path + std::string(legacy_main_extensions[i]);
@@ -2970,7 +2957,7 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
29702957
return;
29712958
}
29722959

2973-
FromNamespacedPath(&initial_file_path.value());
2960+
node::url::FromNamespacedPath(&initial_file_path.value());
29742961

29752962
for (int i = legacy_main_extensions_with_main_end;
29762963
i < legacy_main_extensions_package_fallback_end;

src/node_url.cc

+13
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,19 @@ std::optional<std::string> FileURLToPath(Environment* env,
536536
#endif // _WIN32
537537
}
538538

539+
// Reverse the logic applied by path.toNamespacedPath() to create a
540+
// namespace-prefixed path.
541+
void FromNamespacedPath(std::string* path) {
542+
#ifdef _WIN32
543+
if (path->compare(0, 8, "\\\\?\\UNC\\", 8) == 0) {
544+
*path = path->substr(8);
545+
path->insert(0, "\\\\");
546+
} else if (path->compare(0, 4, "\\\\?\\", 4) == 0) {
547+
*path = path->substr(4);
548+
}
549+
#endif
550+
}
551+
539552
} // namespace url
540553

541554
} // 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(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)