-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Add a checkOpExists helper for common code pattern. NFC #23305
Conversation
We frequently check if a node op is present, if not raise a specific error, if it is present call it. This factors out this common pattern.
if (!node.node_ops.setattr) { | ||
throw new FS.ErrnoError({{{ cDefs.EPERM }}}); | ||
} |
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 changes which error we throw if there are multiple problems.
@@ -1044,7 +1033,7 @@ FS.staticInit(); | |||
utime(path, atime, mtime) { | |||
var lookup = FS.lookupPath(path, { follow: true }); | |||
var node = lookup.node; | |||
node.node_ops.setattr(node, { |
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.
Previously there was no error handling for setattr
being missing, so if we called utime
on a read only node it would crash.
This is an automatic change generated by tools/maint/rebaseline_tests.py. The following (18) test expectation files were updated by running the tests with `--rebaseline`: ``` other/codesize/test_codesize_cxx_ctors1.gzsize: 8365 => 8379 [+14 bytes / +0.17%] other/codesize/test_codesize_cxx_ctors1.jssize: 20373 => 20384 [+11 bytes / +0.05%] other/codesize/test_codesize_cxx_ctors2.gzsize: 8347 => 8365 [+18 bytes / +0.22%] other/codesize/test_codesize_cxx_ctors2.jssize: 20341 => 20352 [+11 bytes / +0.05%] other/codesize/test_codesize_cxx_except.gzsize: 9369 => 9376 [+7 bytes / +0.07%] other/codesize/test_codesize_cxx_except.jssize: 24141 => 24152 [+11 bytes / +0.05%] other/codesize/test_codesize_cxx_except_wasm.gzsize: 8328 => 8340 [+12 bytes / +0.14%] other/codesize/test_codesize_cxx_except_wasm.jssize: 20267 => 20278 [+11 bytes / +0.05%] other/codesize/test_codesize_cxx_except_wasm_exnref.gzsize: 8328 => 8340 [+12 bytes / +0.14%] other/codesize/test_codesize_cxx_except_wasm_exnref.jssize: 20267 => 20278 [+11 bytes / +0.05%] other/codesize/test_codesize_cxx_lto.gzsize: 8360 => 8372 [+12 bytes / +0.14%] other/codesize/test_codesize_cxx_lto.jssize: 20397 => 20408 [+11 bytes / +0.05%] other/codesize/test_codesize_cxx_mangle.gzsize: 9374 => 9381 [+7 bytes / +0.07%] other/codesize/test_codesize_cxx_mangle.jssize: 24142 => 24153 [+11 bytes / +0.05%] other/codesize/test_codesize_cxx_noexcept.gzsize: 8365 => 8379 [+14 bytes / +0.17%] other/codesize/test_codesize_cxx_noexcept.jssize: 20373 => 20384 [+11 bytes / +0.05%] other/codesize/test_codesize_files_js_fs.gzsize: 7655 => 7672 [+17 bytes / +0.22%] other/codesize/test_codesize_files_js_fs.jssize: 18867 => 18879 [+12 bytes / +0.06%] Average change: +0.10% (+0.05% - +0.22%) ```
I'm surprised that this increased code size by a few bytes... |
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.
Nice! That looks much better. Can you rename to to something less overloaded though? checkExists sounds like it will check for file existence, no?
|
src/library_fs.js
Outdated
throw new FS.ErrnoError({{{ cDefs.ENOTDIR }}}); | ||
} | ||
return node.node_ops.readdir(node); | ||
var readdir = FS.checkExists(node.node_ops.readdir, {{{ cDefs.ENOTDIR }}}); |
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.
How about checkAttribute
? Or getAttribute
? Or maybe checkFSOp
? Or checkOpExists
?
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 like checkOpExists
the best.
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 % name bikeshedding. Its kind of shame that FS is a public API.. there is no easy way for us to stop external folks calling this function.
Indeed. |
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.
An alternative to this would be to force all FS impls to implement all operations, and have them report correct errors when they don't, but maybe thats a bigger change..
I find it quite convenient that they default to ENOSYS personally. |
Though maybe |
This is an automatic change generated by tools/maint/rebaseline_tests.py. The following (18) test expectation files were updated by running the tests with `--rebaseline`: ``` other/codesize/test_codesize_cxx_ctors1.gzsize: 8343 => 8350 [+7 bytes / +0.08%] other/codesize/test_codesize_cxx_ctors1.jssize: 20271 => 20272 [+1 bytes / +0.00%] other/codesize/test_codesize_cxx_ctors2.gzsize: 8325 => 8334 [+9 bytes / +0.11%] other/codesize/test_codesize_cxx_ctors2.jssize: 20239 => 20240 [+1 bytes / +0.00%] other/codesize/test_codesize_cxx_except.gzsize: 9346 => 9349 [+3 bytes / +0.03%] other/codesize/test_codesize_cxx_except.jssize: 24039 => 24040 [+1 bytes / +0.00%] other/codesize/test_codesize_cxx_except_wasm.gzsize: 8288 => 8296 [+8 bytes / +0.10%] other/codesize/test_codesize_cxx_except_wasm.jssize: 20164 => 20165 [+1 bytes / +0.00%] other/codesize/test_codesize_cxx_except_wasm_exnref.gzsize: 8288 => 8296 [+8 bytes / +0.10%] other/codesize/test_codesize_cxx_except_wasm_exnref.jssize: 20164 => 20165 [+1 bytes / +0.00%] other/codesize/test_codesize_cxx_lto.gzsize: 8357 => 8364 [+7 bytes / +0.08%] other/codesize/test_codesize_cxx_lto.jssize: 20347 => 20348 [+1 bytes / +0.00%] other/codesize/test_codesize_cxx_mangle.gzsize: 9351 => 9355 [+4 bytes / +0.04%] other/codesize/test_codesize_cxx_mangle.jssize: 24039 => 24040 [+1 bytes / +0.00%] other/codesize/test_codesize_cxx_noexcept.gzsize: 8343 => 8350 [+7 bytes / +0.08%] other/codesize/test_codesize_cxx_noexcept.jssize: 20271 => 20272 [+1 bytes / +0.00%] other/codesize/test_codesize_files_js_fs.gzsize: 7650 => 7652 [+2 bytes / +0.03%] other/codesize/test_codesize_files_js_fs.jssize: 18817 => 18819 [+2 bytes / +0.01%] Average change: +0.04% (+0.00% - +0.11%) ```
Oh, lets try to remember to prefix the PR titles for these changes with |
We frequently check if a node op is present, if not raise a specific error, if it is present call it. This factors out this common pattern.