Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upfs: introduce `opendir()` and `fs.Dir` #29349
+1,165
−119
Conversation
This comment has been minimized.
This comment has been minimized.
|
Also: Very nice work! I’m excited to see this happen :) |
This comment has been minimized.
This comment has been minimized.
|
Few missing commas in documentation spottable with |
|
LGTM with a few comments |
Fishrock123
added a commit
to Fishrock123/node
that referenced
this pull request
Sep 5, 2019
Addresses most of addaleax's 3rd(?) review: nodejs#29349 (review)
|
Looks good! |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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: nodejs/node-v0.x-archive#388 Refs: #583 Refs: libuv/libuv#2057
cf9574e
to
018fc76
This comment has been minimized.
This comment has been minimized.
|
Anyone else want to |
Fishrock123
added a commit
that referenced
this pull request
Oct 8, 2019
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: nodejs/node-v0.x-archive#388 Refs: #583 Refs: libuv/libuv#2057 PR-URL: #29349 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: David Carlier <devnexen@gmail.com>
This comment has been minimized.
This comment has been minimized.
|
Landed in cbd8d71! |
This comment has been minimized.
This comment has been minimized.
|
Outstanding work @Fishrock123 |
BridgeAR
added a commit
that referenced
this pull request
Oct 9, 2019
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: nodejs/node-v0.x-archive#388 Refs: #583 Refs: libuv/libuv#2057 PR-URL: #29349 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: David Carlier <devnexen@gmail.com>
addaleax
added a commit
to nodejs/quic
that referenced
this pull request
Oct 9, 2019
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: nodejs/node-v0.x-archive#388 Refs: nodejs/node#583 Refs: libuv/libuv#2057 PR-URL: nodejs/node#29349 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: David Carlier <devnexen@gmail.com>
addaleax
added a commit
to nodejs/quic
that referenced
this pull request
Oct 9, 2019
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: nodejs/node-v0.x-archive#388 Refs: nodejs/node#583 Refs: libuv/libuv#2057 PR-URL: nodejs/node#29349 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: David Carlier <devnexen@gmail.com>
BridgeAR
added a commit
that referenced
this pull request
Oct 10, 2019
Notable changes:
* build:
* Add `--force-context-aware` flag to prevent usage of native node
addons that aren't context aware
#29631
* deprecations:
* Add documentation-only deprecation for `process._tickCallback()`
#29781
* esm:
* Using JSON modules is experimental again
#29754
* fs:
* Introduce `opendir()` and `fs.Dir` to iterate through directories
#29349
* process:
* Add source-map support to stack traces by using
`--source-map-support` #29564
* tls:
* Honor `pauseOnConnect` option
#29635
* Add option for private keys for OpenSSL engines
#28973
PR-URL: TBD
Merged
BridgeAR
added a commit
that referenced
this pull request
Oct 10, 2019
Notable changes:
* build:
* Add `--force-context-aware` flag to prevent usage of native node
addons that aren't context aware
#29631
* deprecations:
* Add documentation-only deprecation for `process._tickCallback()`
#29781
* esm:
* Using JSON modules is experimental again
#29754
* fs:
* Introduce `opendir()` and `fs.Dir` to iterate through directories
#29349
* process:
* Add source-map support to stack traces by using
`--source-map-support` #29564
* tls:
* Honor `pauseOnConnect` option
#29635
* Add option for private keys for OpenSSL engines
#28973
PR-URL: #29919
BridgeAR
added a commit
that referenced
this pull request
Oct 10, 2019
Notable changes:
* build:
* Add `--force-context-aware` flag to prevent usage of native node
addons that aren't context aware
#29631
* deprecations:
* Add documentation-only deprecation for `process._tickCallback()`
#29781
* esm:
* Using JSON modules is experimental again
#29754
* fs:
* Introduce `opendir()` and `fs.Dir` to iterate through directories
#29349
* process:
* Add source-map support to stack traces by using
`--source-map-support` #29564
* tls:
* Honor `pauseOnConnect` option
#29635
* Add option for private keys for OpenSSL engines
#28973
PR-URL: #29919
BridgeAR
added a commit
that referenced
this pull request
Oct 11, 2019
Notable changes:
* build:
* Add `--force-context-aware` flag to prevent usage of native node
addons that aren't context aware
#29631
* deprecations:
* Add documentation-only deprecation for `process._tickCallback()`
#29781
* esm:
* Using JSON modules is experimental again
#29754
* fs:
* Introduce `opendir()` and `fs.Dir` to iterate through directories
#29349
* process:
* Add source-map support to stack traces by using
`--source-map-support` #29564
* tls:
* Honor `pauseOnConnect` option
#29635
* Add option for private keys for OpenSSL engines
#28973
PR-URL: #29919
BridgeAR
added a commit
that referenced
this pull request
Oct 11, 2019
Notable changes:
* build:
* Add `--force-context-aware` flag to prevent usage of native node
addons that aren't context aware
#29631
* deprecations:
* Add documentation-only deprecation for `process._tickCallback()`
#29781
* esm:
* Using JSON modules is experimental again
#29754
* fs:
* Introduce `opendir()` and `fs.Dir` to iterate through directories
#29349
* process:
* Add source-map support to stack traces by using
`--source-map-support` #29564
* tls:
* Honor `pauseOnConnect` option
#29635
* Add option for private keys for OpenSSL engines
#28973
PR-URL: #29919
addaleax
added a commit
to nodejs/quic
that referenced
this pull request
Oct 11, 2019
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: nodejs/node-v0.x-archive#388 Refs: nodejs/node#583 Refs: libuv/libuv#2057 PR-URL: nodejs/node#29349 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: David Carlier <devnexen@gmail.com>
codebytere
added a commit
to electron/electron
that referenced
this pull request
Oct 15, 2019
introduced in nodejs/node#29349
codebytere
added a commit
to electron/electron
that referenced
this pull request
Oct 15, 2019
introduced in nodejs/node#29349
codebytere
added a commit
to electron/electron
that referenced
this pull request
Oct 15, 2019
introduced in nodejs/node#29349
codebytere
added a commit
to electron/electron
that referenced
this pull request
Oct 16, 2019
introduced in nodejs/node#29349
codebytere
added a commit
to electron/electron
that referenced
this pull request
Oct 16, 2019
introduced in nodejs/node#29349
codebytere
added a commit
to electron/electron
that referenced
this pull request
Oct 17, 2019
introduced in nodejs/node#29349
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Fishrock123 commentedAug 28, 2019
•
edited
This adds long-requested methods for asynchronously interacting and iterating through directory entries by using
uv_fs_opendir,uv_fs_readdir, anduv_fs_closedir.fs.opendir()and friends return anfs.Dir, which contains methods for doing reads and cleanup.fs.Diralso has the async iterator symbol exposed.The
read()method and friends only returnfs.Dirents for this API.Having a entry type or doing a
statcall 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
nullinstead 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:
Makinguv_dir_tkeep a record of its path (or a way to retrieve it).readv()to do multi-entry directory reads.fs.readdirtofs.scandirand doing a deprecation.Refs: nodejs/node-v0.x-archive#388
Refs: #583
Refs: libuv/libuv#2057
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesI am open to discussing the api shapes, I found that this
fs.Dirapi made it easiest to reconcile the callback and promise apis into "one" reasonably nice (hopefully future proof) api, but I feel folks might have strong feelings about that. It does make a bit of mess in the docs though.Also please tell me any C++ nonsense I got terribly wrong, haha.