-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
Inconsistent behavior with fs module accross platforms #17801
Comments
Thanks for reporting this issue! So require('fs').wrtieFileSync('test/', 'smth');
Yep, this looks like a bug for me. @nodejs/fs |
@bzoz I don't know if am looking at the right place, But after looking at this line commet https://github.com/libuv/libuv/blob/2b32e77bb6f41e2786168ec0f32d1f0fcc78071b/src/win/fs.c#L519 |
Throw Error if path ends with `/` only on windows linux is behaving as expected. As suggested by issues nodejs#17801
Previously upon calling file-only fs functions with a directory (or presumably a directory of path ending with a forward slash '/') it would result in EISDIR error on Linux but Windows would completely ignore trailing '/' and perform operation on a file excluding it. This introduces additional checks in fs code to make sure the trailing slash is handled the same way across systems. Fixes: nodejs#17801
This reverts commit 00b2f07. PR-URL: #55527 Fixes: #17801 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Stefan Stojanovic <stefan.stojanovic@janeasystems.com>
Fixes: nodejs#17801 Refs: nodejs#33831 PR-URL: nodejs#54160 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
This reverts commit 00b2f07. PR-URL: nodejs#55527 Fixes: nodejs#17801 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Stefan Stojanovic <stefan.stojanovic@janeasystems.com>
Reopening because of #55527 |
This reverts commit 00b2f07. PR-URL: #55527 Fixes: #17801 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Stefan Stojanovic <stefan.stojanovic@janeasystems.com>
In Windows, if a file name ends with forward slash (
/
),fs
interprets it as regular file (like there is no slash at all) and does not throw any errors. In Linux, it throws errorIMO, fs should either throw the same error in Windows, or don't throw the error in Linux.
Of course, when we talk about file name consistency, there will always be some characters which are allowed in Linux, but not allowed in Windows (like
\u0001
), but that inconsistency is a result of the way OS handles these situations. However, if a file name ends with a forward slash, it either means that someone mistakenly tried to open directory as a file, or just have forgotten to remove the slash. Therefore,fs
should be consistent with the way it handles forward slash at the end of the file name. It means: either throw error always, or behave like there is no slash.I made a script which shows how it currently works.
The text was updated successfully, but these errors were encountered: