Uh oh!
There was an error while loading. Please reload this page.
fs: add mkstemp functions - #33549
Conversation
* fs.mkstemp and fs.mkstempSync return `path` and `fd`. * fsPromises.mkstemp returns `path` and `handle`.
targos
commented
May 25, 2020
/cc @addaleax |
Uh oh!
There was an error while loading. Please reload this page.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
nodejs-github-bot
commented
May 25, 2020
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
benjamingr
commented
May 25, 2020
I think a disposer API for the promises side would have been nicer. I maintain I'd also steal some tests from |
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Benjamin Gruenbaum <inglor@gmail.com>
Uh oh!
There was an error while loading. Please reload this page.
targos
commented
May 25, 2020
I don't understand what you are suggesting, sorry. |
benjamingr
commented
May 25, 2020
@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. |
Uh oh!
There was an error while loading. Please reload this page.
targos
commented
May 30, 2020
@nodejs/platform-aix PTAL |
richardlau
commented
May 30, 2020
I can take a look on Monday but my suspicion would be that the value of the template (i.e. |
bnoordhuis
left a comment
There was a problem hiding this comment.
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.
bnoordhuis
commented
May 30, 2020
That sounds plausible. POSIX allows it to be unspecified. I'll open a libuv PR to clobber |
8ae28ff to
2935f72Comparerichardlau
commented
Jun 1, 2020
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 ( |
targos
commented
Jul 14, 2020
@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? |
bnoordhuis
commented
Jul 14, 2020
@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:
|
targos
commented
Jul 14, 2020
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 <vtjnash@gmail.com>
aduh95
commented
Oct 16, 2020
targos
commented
Oct 17, 2020
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 <vtjnash@gmail.com>
mschfh
commented
Aug 22, 2023
Could this PR be merged and the enhancement be added later on? |
BrianJDrake
commented
Oct 14, 2023
This pull request would complete the old feature request #5332. |
targos
commented
Oct 17, 2023
Anyone feel free to take this over. I'm not able to fix the problems and I don't need the feature myself. |
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/libuv#2913 Refs: nodejs/node#33549 Refs: libuv/libuv#2933 PR-URL: libuv/libuv#2938 Reviewed-By: Jameson Nash <vtjnash@gmail.com>
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/libuv#2913 Refs: nodejs/node#33549 Refs: libuv/libuv#2933 PR-URL: libuv/libuv#2938 Reviewed-By: Jameson Nash <vtjnash@gmail.com>
pathandfd.pathandhandle.@nodejs/fs
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes