-
Notifications
You must be signed in to change notification settings - Fork 30k
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: add mkstemp functions #33549
fs: add mkstemp functions #33549
Conversation
* fs.mkstemp and fs.mkstempSync return `path` and `fd`. * fsPromises.mkstemp returns `path` and `handle`.
/cc @addaleax |
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
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I think a disposer API for the promises side would have been nicer. I maintain I'd also steal some tests from |
Co-authored-by: Benjamin Gruenbaum <[email protected]>
I don't understand what you are suggesting, sorry. |
@targos in fs.promises.withMkstemp(async (file) => {
// when the promise returned from this async function settles, file is automatically closed
}); This makes for better error handling most of the time. I am not saying we should ship this sort of API or that if we do we shouldn't ship the one already in this PR - only that in my (anecdotal) experience as a maintainer of tmp-promise it's the more popular one. |
Test failed on AIX: https://ci.nodejs.org/job/node-test-commit-aix/30706/nodes=aix71-ppc64/testReport/junit/(root)/test/parallel_test_fs_error_messages/ Any idea why? |
@nodejs/platform-aix PTAL |
I can take a look on Monday but my suspicion would be that the value of the template (i.e. |
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. The AIX failure looks like it's happening on the libuv or libc level. Needs further investigation but I don't think it's caused by this PR.
That sounds plausible. POSIX allows it to be unspecified. I'll open a libuv PR to clobber |
8ae28ff
to
2935f72
Compare
Yes, looks like that's the case here: diff --git a/deps/uv/src/unix/fs.c b/deps/uv/src/unix/fs.c
index f5b2b94207..ce9683cb51 100644
--- a/deps/uv/src/unix/fs.c
+++ b/deps/uv/src/unix/fs.c
@@ -336,7 +336,9 @@ static int uv__fs_mkstemp(uv_fs_t* req) {
if (req->cb != NULL)
uv_rwlock_rdlock(&req->loop->cloexec_lock);
+printf("before mkstemp, path: %s\n", path);
r = mkstemp(path);
+printf("after mkstemp, path: %s\n", path);
/* In case of failure `uv__cloexec` will leave error in `errno`,
* so it is enough to just set `r` to `-1`.
POSIX doesn't specify what happens to the template string in the error case: https://pubs.opengroup.org/onlinepubs/9699919799/functions/mkdtemp.html The Linux documentation also points out that the template may be undefined for some errors (EEXIST): https://www.man7.org/linux/man-pages/man3/mkstemp.3.html So it's not safe to assume the contents of the template ( |
@bnoordhuis I'm not sure anymore. Is this blocked on work that should be done on the libuv side, or should I do something here to fix the issue? |
@targos There's still some work to be done in libuv but nothing critical, it doesn't have to hold up this PR. I'd go with Richard's suggestion:
|
Okay, can you help me do it? I don't know how I could access the value from the |
Contents of template variable passed for posix call mkstemp on error code EINVAL is unknown. On AIX platform, template will get clobbered on EINVAL and any attempt to read template might result in error. In libuv, req->path is passed directly to the mkstemp call and behavior of this string on error is platform dependent. To avoid portability issues, it's better to have a common behavior on all platform. For both unix and windows platform libuv will rewrite path with an empty string on all error cases. Fixes: #2913 Refs: nodejs/node#33549 Refs: #2933 PR-URL: #2938 Reviewed-By: Jameson Nash <[email protected]>
It doesn't. I still need help for #33549 (comment) |
Contents of template variable passed for posix call mkstemp on error code EINVAL is unknown. On AIX platform, template will get clobbered on EINVAL and any attempt to read template might result in error. In libuv, req->path is passed directly to the mkstemp call and behavior of this string on error is platform dependent. To avoid portability issues, it's better to have a common behavior on all platform. For both unix and windows platform libuv will rewrite path with an empty string on all error cases. Fixes: libuv#2913 Refs: nodejs/node#33549 Refs: libuv#2933 PR-URL: libuv#2938 Reviewed-By: Jameson Nash <[email protected]>
Could this PR be merged and the enhancement be added later on? |
This pull request would complete the old feature request #5332. |
Anyone feel free to take this over. I'm not able to fix the problems and I don't need the feature myself. |
path
andfd
.path
andhandle
.@nodejs/fs
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes