-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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: return stats to JS in sync methods #20167
Conversation
- Reduce reference to the global `statValues` by returning the changed stats array from the synchronous methods. Having a local returned value also makes the future integration of BigInt easier. - Also returns the filled array from node::FillGlobalStatsArray and node::FillStatsArray in the C++ side.
cc @nodejs/fs |
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 if the benchmarks show no regression.
lib/fs.js
Outdated
@@ -1682,10 +1685,10 @@ fs.realpathSync = function realpathSync(p, options) { | |||
|
|||
var baseLong = pathModule.toNamespacedPath(base); | |||
const ctx = { path: base }; | |||
binding.lstat(baseLong, undefined, ctx); | |||
const arr = binding.lstat(baseLong, undefined, ctx); |
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.
Nit: arr
seems pretty generic. Should it not be stats like everywhere else?
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.
Benchmarks look good 👍
@@ -1666,7 +1668,8 @@ fs.realpathSync = function realpathSync(p, options) { | |||
|
|||
// continue if not a symlink, break if a pipe/socket | |||
if (knownHard[base] || (cache && cache.get(base) === base)) { | |||
if (isFileType(S_IFIFO) || isFileType(S_IFSOCK)) { | |||
if (isFileType(statValues, S_IFIFO) || | |||
isFileType(statValues, S_IFSOCK)) { |
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.
statValues
is filled up by the binding.lstat()
call ~20 lines up? Is the logic here still correct if the entry comes from the cache?
Apropos that lstat()
call, maybe do this?
let stats; // and use this in isFileType() calls
if (...) {
const ctx = { path: base };
stats = binding.lstat(pathModule.toNamespacedPath(base), undefined, ctx);
// ...
}
(Also applies to fs.realpath()
.)
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.
In the current code statValues
always equals to stats
since neither side allocate any new stats arrays. I could try this but from the code it's very hard to tell if stats will be undefined
or not when you hit the use statement below.
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.
Okay, never mind then.
lib/fs.js
Outdated
@@ -1820,14 +1824,14 @@ fs.realpath = function realpath(p, options, callback) { | |||
return fs.lstat(base, gotStat); | |||
} | |||
|
|||
function gotStat(err) { | |||
function gotStat(err, stats) { | |||
if (err) return callback(err); | |||
|
|||
// Use stats array directly to avoid creating an fs.Stats instance just for | |||
// our internal use. |
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.
No longer true, is it?
Addressed the nits. CI is green, landing... |
Landed in ce4c8c8, thanks! |
- Reduce reference to the global `statValues` by returning the changed stats array from the synchronous methods. Having a local returned value also makes the future integration of BigInt easier. - Also returns the filled array from node::FillGlobalStatsArray and node::FillStatsArray in the C++ side. PR-URL: #20167 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Khaidi Chu <[email protected]> Reviewed-By: Gus Caplan <[email protected]>
- Reduce reference to the global `statValues` by returning the changed stats array from the synchronous methods. Having a local returned value also makes the future integration of BigInt easier. - Also returns the filled array from node::FillGlobalStatsArray and node::FillStatsArray in the C++ side. PR-URL: #20167 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Khaidi Chu <[email protected]> Reviewed-By: Gus Caplan <[email protected]>
This causes issues on Windows: #19831 (comment) |
statValues
by returningthe changed stats array from the synchronous methods. Having
a local returned value also makes the future integration
of BigInt easier.
and node::FillStatsArray in the C++ side.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes