Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 36.4k
fs: handle fixes#45909
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
Uh oh!
There was an error while loading. Please reload this page.
fs: handle fixes #45909
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -80,15 +80,22 @@ function _construct(callback) { | ||
| } | ||
| // This generates an fs operations structure for a FileHandle | ||
| const FileHandleOperations = (handle) => { | ||
| const FileHandleOperations = (handle, closeHandler) => { | ||
| return { | ||
| open: (path, flags, mode, cb) => { | ||
| throw new ERR_METHOD_NOT_IMPLEMENTED('open()'); | ||
| }, | ||
| close: (fd, cb) => { | ||
| handle.off('close', closeHandler); | ||
MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid keeping stream alive until file handle is closed. | ||
| handle[kUnref](); | ||
| PromisePrototypeThen(handle.close(), | ||
| () => cb(), cb); | ||
| if (handle[kFd] !== -1) { | ||
| // Someone else has a ref to the handle. | ||
| process.nextTick(cb); | ||
MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. stream can finish teardown even if file handle isn't closed, if it has refs | ||
| } else { | ||
| PromisePrototypeThen(handle.close(), | ||
| () => cb(), cb); | ||
| } | ||
| }, | ||
| read: (fd, buf, offset, length, pos, cb) => { | ||
| PromisePrototypeThen(handle.read(buf, offset, length, pos), | ||
| @@ -134,11 +141,14 @@ function importFd(stream, options) { | ||
| // FileHandle is not supported with custom fs operations | ||
| throw new ERR_METHOD_NOT_IMPLEMENTED('FileHandle with fs'); | ||
| } | ||
| const closeHandler = FunctionPrototypeBind(stream.close, stream); | ||
| stream[kHandle] = options.fd; | ||
| stream[kFs] = FileHandleOperations(stream[kHandle]); | ||
| stream[kFs] = FileHandleOperations(stream[kHandle], closeHandler); | ||
| stream[kHandle][kRef](); | ||
| options.fd.on('close', FunctionPrototypeBind(stream.close, stream)); | ||
| return options.fd.fd; | ||
| stream[kHandle].on('close', closeHandler); | ||
| return stream[kHandle].fd; | ||
| } | ||
| throw ERR_INVALID_ARG_TYPE('options.fd', | ||
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.
Only emit close after actually closing.