-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fs,win: fix bug in paths with trailing slashes #54160
fs,win: fix bug in paths with trailing slashes #54160
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #54160 +/- ##
==========================================
+ Coverage 87.07% 87.10% +0.03%
==========================================
Files 643 647 +4
Lines 181583 181816 +233
Branches 34886 34895 +9
==========================================
+ Hits 158114 158375 +261
+ Misses 16751 16745 -6
+ Partials 6718 6696 -22
|
31da37f
to
c93a41e
Compare
c93a41e
to
733558f
Compare
lib/internal/fs/utils.js
Outdated
@@ -709,14 +709,30 @@ const validateOffsetLengthWrite = hideStackFrames( | |||
}, | |||
); | |||
|
|||
const validatePath = hideStackFrames((path, propName = 'path') => { | |||
const validatePath = hideStackFrames((path, propName = 'path', isFile) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a JSDoc to this function and adding a small comment that explains the behavior of this new flag?
const validatePath = hideStackFrames((path, propName = 'path', isFile) => { | |
const validatePath = hideStackFrames((path, propName = 'path', expectFile) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
lib/internal/fs/utils.js
Outdated
code: 'ERR_FS_EISDIR', | ||
message: 'is a directory', | ||
path, | ||
syscall: 'validatePath', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
syscall: 'validatePath', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a syscall.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've applied the fix you suggested, but as you can see the CI doesn't accept throwing an error without a syscall. I didn't get this on Windows, only Linux.
This function is being called from a number of functions that contain different syscalls. Do you have any idea what I can write here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this syscall
should be the name of the fs
caller function. Maybe passing it as an argument would be the correct call here? For example, if fs.cpSync()
is throwing this error, syscall should be cp
. IMHO, Ideally we should throw this error from C++.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review. Fixed.
lib/internal/fs/utils.js
Outdated
* @throws {TypeError} Throws if the path is not a string, Uint8Array, or URL without null bytes. | ||
* @throws {Error} Throws if the path does not meet the expected type (file). | ||
*/ | ||
const validatePath = hideStackFrames((path, propName = 'path', expectFile) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we should go for options
instead of expectFile
and pass { expectFile: true, syscall: 'cp' }
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And just check for options != null
in 729?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
cc @nodejs/fs @nodejs/performance |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
I have a rough feeling that we might be better to land this as semver-major, or at the bare minimum to not backport to v20 and v18. Wdyt? |
That's my feeling too. I'd not land it on 22 too. Honestly, I'm not confident this design is good/desirable. I can see people forgetting to pass such parameters in a future fs API. |
Is there anything else I can do to help this PR move forward? |
@anonrig @RafaelGSS PTAL |
Can someone take a look at this PR? |
Landed in 00b2f07 |
This landed without a recent CI run, resulting in failing linter on |
@huseyinacacak-janea @anonrig This change will cause webpack on windows to fail to save cache files. Remove the following lines of code and recompile node.js to restore to normal. I'm not sure if the problem lies with webpack or here.
I wrote an example project that can reproduce this error https://github.com/ShenHongFei/webpack-bug webpack error log
|
This also causes trouble for emscripten: emscripten-core/emscripten#22812 |
Fixes: nodejs#17801 Refs: nodejs#33831 PR-URL: nodejs#54160 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]>
Fixes: nodejs#17801 Refs: nodejs#33831 PR-URL: nodejs#54160 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]>
This PR fixes the inconsistency across platforms by throwing the same exception on Windows as on Linux.
I've taken the logic and the code in the referenced PR and modified it slightly to allow it to run with the current implementation of Node. Thanks @lundibundi.
Fixes: #17801
Refs: #33831