Skip to content

module,win: fix long path resolve - #53294

Merged
nodejs-github-bot merged 3 commits into
nodejs:mainfrom
JaneaSystems:huseyin-11801-long-path-error
Aug 10, 2024
Merged

module,win: fix long path resolve#53294
nodejs-github-bot merged 3 commits into
nodejs:mainfrom
JaneaSystems:huseyin-11801-long-path-error

Conversation

@huseyinacacak-janea

Copy link
Copy Markdown
Contributor

Several issues were encountered with module loading due to extended path lengths on Windows. These have been addressed with corrections implemented across four distinct code locations, accompanied by the addition of a corresponding test case for each to ensure functionality.
Additionally, I've moved es-module/test-GH-50753.js to es-module/test-esm-long-path-win.js as the tests cover more cases than specified in that issue.

Fixes: #50753

@nodejs-github-botnodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. fs Issues and PRs related to the fs subsystem / file system. needs-ci PRs that need a full CI run. labels Jun 3, 2024
@targos

Copy link
Copy Markdown
Member

@nodejs/platform-windows

@huseyinacacak-janea
huseyinacacak-janeaforce-pushed the huseyin-11801-long-path-error branch from 3ee742c to 27a4505CompareJune 3, 2024 12:11
H4ad
H4ad previously approved these changes Jun 3, 2024
@H4ad
H4ad dismissed their stale reviewJune 3, 2024 12:53

I actually need more time to take a look, I think the implementation will solve the problem but I want to test in which cases we should include the UNC path, since we didn't do this in all paths in the toNamespacedPath.

@H4ad

H4ad commented Jun 3, 2024

Copy link
Copy Markdown
Member

There are some conditions to include the UNC that you are not following:

node/lib/path.js

Lines 632 to 645 in 58711c2

if(StringPrototypeCharCodeAt(resolvedPath,0)===CHAR_BACKWARD_SLASH){
// Possible UNC root
if(StringPrototypeCharCodeAt(resolvedPath,1)===CHAR_BACKWARD_SLASH){
constcode=StringPrototypeCharCodeAt(resolvedPath,2);
if(code!==CHAR_QUESTION_MARK&&code!==CHAR_DOT){
// Matched non-long UNC root, convert the path to a long UNC path
return`\\\\?\\UNC\\${StringPrototypeSlice(resolvedPath,2)}`;
}
}
}elseif(
isWindowsDeviceRoot(StringPrototypeCharCodeAt(resolvedPath,0))&&
StringPrototypeCharCodeAt(resolvedPath,1)===CHAR_COLON&&
StringPrototypeCharCodeAt(resolvedPath,2)===CHAR_BACKWARD_SLASH
){

Although the condition could be matched, I think it would be better to wait for the migration of toNamespacedPath to C++.

Maybe we could include the ToNamespacePath port in this PR, and then leave that other PR just to remove the JS version and rewrite the places they are used.

@anonrig What do you think?

@StefanStojanovicStefanStojanovic added the request-ci Add this label to start a Jenkins CI on a PR. label Jun 3, 2024
@github-actionsgithub-actionsBot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jun 3, 2024
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/59635/

@anonriganonrig left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to land this after the toNamespacedPath migration to C++. Unfortunately, I don't have the time to pursue this at the moment (afaict, there is only one failing test). I appreciate if you could took over that PR and apply these changes in a follow up PR.

@MoLow

MoLow commented Jun 3, 2024

Copy link
Copy Markdown
Member

I prefer to land this after the toNamespacedPath migration to C++. Unfortunately, I don't have the time to pursue this at the moment (afaict, there is only one failing test). I appreciate if you could took over that PR and apply these changes in a follow up PR.

in that case, can you convert the blocking "request changes" into a simple suggestion/friendly ask? I don't think this PR should be blocked on a PR that is not being currently worked on

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/59644/

@huseyinacacak-janea

Copy link
Copy Markdown
ContributorAuthor

I prefer to land this after the toNamespacedPath migration to C++. Unfortunately, I don't have the time to pursue this at the moment (afaict, there is only one failing test). I appreciate if you could took over that PR and apply these changes in a follow up PR.

Sure, no problem, I'll take over your PR and start working on it.

@huseyinacacak-janea
huseyinacacak-janeaforce-pushed the huseyin-11801-long-path-error branch from 27a4505 to 42b88bfCompareJuly 1, 2024 09:31
@huseyinacacak-janea
huseyinacacak-janeaforce-pushed the huseyin-11801-long-path-error branch from 42b88bf to 14a1de0CompareJuly 2, 2024 05:37
@StefanStojanovicStefanStojanovic added the request-ci Add this label to start a Jenkins CI on a PR. label Jul 2, 2024
H4ad
H4ad approved these changes Jul 2, 2024
@github-actionsgithub-actionsBot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 3, 2024
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/60050/

@huseyinacacak-janea

Copy link
Copy Markdown
ContributorAuthor

I prefer to land this after the toNamespacedPath migration to C++. Unfortunately, I don't have the time to pursue this at the moment (afaict, there is only one failing test). I appreciate if you could took over that PR and apply these changes in a follow up PR.

@anonrig I've rebased this PR to use toNamespacedPath. Could you please review it?

@huseyinacacak-janea

Copy link
Copy Markdown
ContributorAuthor

Is there anything else I can do to help this PR move forward?

@H4ad
H4ad requested a review from anonrigJuly 15, 2024 12:01
Comment threadsrc/node_file.cc Outdated
switch (FilePathIsFile(env, file_path)) {
Local<Value> local_file_path =
Buffer::Copy(
env->isolate(), file_path.c_str(), strlen(file_path.c_str()))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
env->isolate(), file_path.c_str(), strlen(file_path.c_str()))
env->isolate(), file_path.c_str(), file_path.size())

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Thanks.

Comment threadsrc/node_file.cc Outdated
switch (FilePathIsFile(env, file_path)) {
Local<Value> local_file_path =
Buffer::Copy(
env->isolate(), file_path.c_str(), strlen(file_path.c_str()))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Comment threadsrc/node_modules.cc Outdated
// Check if the path has a trailing slash. If so, add it after
// ToNamespacedPath() as it will be deleted by ToNamespacedPath()
bool slashCheck = !path_value.ToString().empty() &&
path_value.ToString().back() ==

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
path_value.ToString().back() ==
path_value.ToStringView().ends_with

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Comment threadsrc/node_modules.cc Outdated
// Check if the path has a trailing slash. If so, add it after
// ToNamespacedPath() as it will be deleted by ToNamespacedPath()
bool slashCheck = !path_value.ToString().empty() &&
path_value.ToString().back() ==

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Comment threadsrc/node_modules.cc Outdated
bool slashCheck = !path_value.ToString().empty() &&
path_value.ToString().back() ==
std::filesystem::path::preferred_separator;
path_value.ToStringView().ends_with(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous line is not needed path_value.ToString() creates an unnecessary string.

Can you also remove this in other places?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Comment threadsrc/node_file.cc
@huseyinacacak-janea

Copy link
Copy Markdown
ContributorAuthor

I've fixed the suggestions. Is there anything else I can do to help this PR move forward?

@QuantumQuin

Copy link
Copy Markdown

@anonrig Is there anything else we can do to help this PR move forward? I'm having many issues with long paths on Windows and am eager to get this fixed.

@anonriganonrig added the request-ci Add this label to start a Jenkins CI on a PR. label Aug 7, 2024
@github-actionsgithub-actionsBot removed the request-ci Add this label to start a Jenkins CI on a PR. label Aug 7, 2024
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@huseyinacacak-janea

Copy link
Copy Markdown
ContributorAuthor

The failing test in the CI is a known flaky test.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@H4adH4ad added commit-queue Add this label to land a pull request using GitHub Actions. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. labels Aug 10, 2024
@nodejs-github-botnodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Aug 10, 2024
@nodejs-github-bot
nodejs-github-bot merged commit 37f9eca into nodejs:mainAug 10, 2024
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in 37f9eca

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++Issues and PRs that require attention from people who are familiar with C++.commit-queue-squashAdd this label to instruct the Commit Queue to squash all the PR commits into the first one.fsIssues and PRs related to the fs subsystem / file system.needs-ciPRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Long node_modules paths cannot be found on Windows when LongPathsEnabled enabled

8 participants

@huseyinacacak-janea@targos@H4ad@nodejs-github-bot@MoLow@QuantumQuin@anonrig@StefanStojanovic