theanarkh
775bf629dd
fs: trace more fs api
...
PR-URL: https://github.com/nodejs/node/pull/45095
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
2022-10-26 16:48:37 +00:00
theanarkh
60c3077d46
src: trace fs async api
...
PR-URL: https://github.com/nodejs/node/pull/44057
Reviewed-By: James M Snell <jasnell@gmail.com >
2022-08-28 18:06:27 +00:00
legendecas
a7e5b413ef
src: split property helpers from node::Environment
...
PR-URL: https://github.com/nodejs/node/pull/44056
Refs: https://github.com/nodejs/node/issues/42528
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com >
Reviewed-By: Feng Yu <F3n67u@outlook.com >
2022-08-02 00:01:02 +08:00
Darshan Sen
fa7cdd6fc9
src: use SPrintF in ProcessEmitWarning
...
PR-URL: https://github.com/nodejs/node/pull/38758
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
2021-05-25 07:16:42 -07:00
Joyee Cheung
8aa9b772f4
bootstrap: include fs module into the builtin snapshot
...
PR-URL: https://github.com/nodejs/node/pull/36943
Fixes: https://github.com/nodejs/node/issues/35930
Refs: https://github.com/nodejs/node/issues/35711
Reviewed-By: James M Snell <jasnell@gmail.com >
2021-02-19 19:08:06 +08:00
Michaël Zasso
b346cd1760
src: avoid implicit type conversions
...
This fixes a bunch of C4244 ('conversion' conversion from 'type1' to
'type2', possible loss of data) MSVC warnings in the code base.
PR-URL: https://github.com/nodejs/node/pull/37149
Reviewed-By: Darshan Sen <raisinten@gmail.com >
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2021-02-07 17:51:41 -08:00
James M Snell
28fe1ef635
src: reduce duplicated boilerplate with new env utility fn
...
Signed-off-by: James M Snell <jasnell@gmail.com >
PR-URL: https://github.com/nodejs/node/pull/36536
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Rich Trott <rtrott@gmail.com >
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com >
2021-01-03 12:58:09 -08:00
Anna Henningsen
4cac54362a
src: remove redundant snprintf
...
PR-URL: https://github.com/nodejs/node/pull/34282
Reviewed-By: Richard Lau <riclau@uk.ibm.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com >
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
Reviewed-By: James M Snell <jasnell@gmail.com >
2020-07-14 15:05:56 +02:00
Daniel Bevenius
4a20cc937f
src: remove unused using declarations
...
This commit removes the unused using declarations reported by lint-cpp.
PR-URL: https://github.com/nodejs/node/pull/33268
Refs: https://github.com/nodejs/node/issues/29226
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl >
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
Reviewed-By: Christian Clauss <cclauss@me.com >
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com >
Reviewed-By: Beth Griggs <Bethany.Griggs@uk.ibm.com >
2020-05-28 10:02:14 -04:00
Anna Henningsen
b6b82cba27
src: use enum for refed flag on native immediates
...
Refs: https://github.com/nodejs/node/pull/33320#discussion_r423141443
PR-URL: https://github.com/nodejs/node/pull/33444
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Zeyu Yang <himself65@outlook.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: David Carlier <devnexen@gmail.com >
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl >
2020-05-21 17:47:56 -07:00
Anna Henningsen
e9f2937507
fs: clean up Dir.read() uv_fs_t data before calling into JS
...
A call into JS can schedule another operation on the same `uv_dir_t`.
In particular, when the handle is closed from the callback for a
directory read operation, there previously was a race condition window:
1. A `dir.read()` operation is submitted to libuv
2. The read operation is finished by libuv, calling `AfterDirRead()`
3. We call into JS
4. JS calls dir.close()
5. libuv posts the close request to a thread in the pool
6. The close request runs, destroying the directory handle
7. `AfterDirRead()` is being exited.
Exiting the `FSReqAfterScope` in step 7 attempts to destroy the original
uv_fs_t` from step 1, which now points to an `uv_dir_t` that has
already been destroyed in step 5.
By forcing the `FSReqAfterScope` to clean up before we call into JS,
we can be sure that no other operations on the same `uv_dir_t` are
submitted concurrently.
This addresses issues observed when running with ASAN/valgrind.
PR-URL: https://github.com/nodejs/node/pull/33274
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
2020-05-15 19:36:48 +02:00
Anna Henningsen
f4c2dff4e6
src: move fs state out of Environment
...
Moves state that is specific to the `fs` binding into the
`fs` binding implementation as a cleanup.
PR-URL: https://github.com/nodejs/node/pull/32538
Reviewed-By: James M Snell <jasnell@gmail.com >
2020-04-06 02:06:43 +02:00
James M Snell
0fac393d26
src: improve handling of internal field counting
...
Change suggested by bnoordhuis.
Improve handing of internal field counting by using enums.
Helps protect against future possible breakage if field
indexes are ever changed or added to.
Signed-off-by: James M Snell <jasnell@gmail.com >
PR-URL: https://github.com/nodejs/node/pull/31960
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com >
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
2020-03-02 10:58:36 -08:00
gengjiawen
1d0c3e3188
src: remove redundant cast in node_dir.cc
...
PR-URL: https://github.com/nodejs/node/pull/30747
Reviewed-By: David Carlier <devnexen@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
2019-12-03 23:21:14 +01:00
Priyanka Kore
efd6775a50
src: fix node_dir.cc memory allocation
...
PR-URL: https://github.com/nodejs/node/pull/30750
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: David Carlier <devnexen@gmail.com >
2019-12-03 23:19:14 +01:00
Anna Henningsen
52a3e35604
src: clean up node_file.h
...
- Move inline functions into an `-inl.h` file
- Move override function definitions into `.cc` files
- Remove `using` statements from header files
- Make data fields of classes private
- Mark classes at the end of hierarchies as `final`
This is also partially being done in an attempt to avoid
a particular internal compiler error, see
https://github.com/nodejs/node/pull/30475#issuecomment-554740850
for details.
PR-URL: https://github.com/nodejs/node/pull/30530
Reviewed-By: Jiawen Geng <technicalcute@gmail.com >
Reviewed-By: David Carlier <devnexen@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2019-11-30 08:51:06 +00:00
gengjiawen
6c4cf862d0
src: remove unused variable in node_dir.cc
...
PR-URL: https://github.com/nodejs/node/pull/30267
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Richard Lau <riclau@uk.ibm.com >
Reviewed-By: David Carlier <devnexen@gmail.com >
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
2019-11-30 08:39:08 +00:00
Anna Henningsen
b35181f877
fs: add bufferSize option to fs.opendir()
...
Add an option that controls the size of the internal
buffer.
Fixes: https://github.com/nodejs/node/issues/29941
PR-URL: https://github.com/nodejs/node/pull/30114
Reviewed-By: Richard Lau <riclau@uk.ibm.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
2019-10-28 14:34:25 +01:00
Anna Henningsen
5c93aab278
fs: buffer dir entries in opendir()
...
Read up to 32 directory entries in one batch when `dir.readSync()`
or `dir.read()` are called.
This increases performance significantly, although it introduces
quite a bit of edge case complexity.
confidence improvement accuracy (*) (**) (***)
fs/bench-opendir.js mode='async' dir='lib' n=100 *** 155.93 % ±30.05% ±40.34% ±53.21%
fs/bench-opendir.js mode='async' dir='test/parallel' n=100 *** 479.65 % ±56.81% ±76.47% ±101.32%
fs/bench-opendir.js mode='sync' dir='lib' n=100 10.38 % ±14.39% ±19.16% ±24.96%
fs/bench-opendir.js mode='sync' dir='test/parallel' n=100 *** 63.13 % ±12.84% ±17.18% ±22.58%
PR-URL: https://github.com/nodejs/node/pull/29893
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: David Carlier <devnexen@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com >
2019-10-11 23:09:39 +02:00
Jeremiah Senkpiel
cbd8d715b2
fs: introduce opendir() and fs.Dir
...
This adds long-requested methods for asynchronously interacting and
iterating through directory entries by using `uv_fs_opendir`,
`uv_fs_readdir`, and `uv_fs_closedir`.
`fs.opendir()` and friends return an `fs.Dir`, which contains methods
for doing reads and cleanup. `fs.Dir` also has the async iterator
symbol exposed.
The `read()` method and friends only return `fs.Dirent`s for this API.
Having a entry type or doing a `stat` call is deemed to be necessary in
the majority of cases, so just returning dirents seems like the logical
choice for a new api.
Reading when there are no more entries returns `null` instead of a
dirent. However the async iterator hides that (and does automatic
cleanup).
The code lives in separate files from the rest of fs, this is done
partially to prevent over-pollution of those (already very large)
files, but also in the case of js allows loading into `fsPromises`.
Due to async_hooks, this introduces a new handle type of `DIRHANDLE`.
This PR does not attempt to make complete optimization of
this feature. Notable future improvements include:
- Moving promise work into C++ land like FileHandle.
- Possibly adding `readv()` to do multi-entry directory reads.
- Aliasing `fs.readdir` to `fs.scandir` and doing a deprecation.
Refs: https://github.com/nodejs/node-v0.x-archive/issues/388
Refs: https://github.com/nodejs/node/issues/583
Refs: https://github.com/libuv/libuv/pull/2057
PR-URL: https://github.com/nodejs/node/pull/29349
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: David Carlier <devnexen@gmail.com >
2019-10-08 10:34:48 -07:00