-
Notifications
You must be signed in to change notification settings - Fork 86
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
EBADF from fs.promises.readFile() and O_CREAT #288
Comments
O_RDONLY is mockfs got confused about the read mode. Lines 82 to 89 in ad93ac5
The implementation should be fixed and simplified as FileDescriptor.prototype.isRead = function() {
return (this._flags & constants.O_WRONLY) !== constants.O_WRONLY;
}; If I understand open(2) man page correctly. http://man7.org/linux/man-pages/man2/open.2.html
O_RDONLY is 0, O_WRONLY is 1, O_RDWR is 2, the flag uses the 2 bits for 3 states: 0 (0b00) / 1 (0b01) / 2 (0b10), the 2 bits will never be 3 (0b11). @tschaub does this fix make sense? |
Note this is not a new bug on promises api, it happens on |
The argument flags must include one of the following access modes: O_RDONLY, O_WRONLY, or O_RDWR. These request opening the file read- only, write-only, or read/write, respectively. O_RDONLY is 0, O_WRONLY is 1, O_RDWR is 2, the flags use 2 bits for 3 states: 0 (0b00) / 1 (0b01) / 2 (0b10), the 2 bits will never be 3 (0b11). closes #288
The argument flags must include one of the following access modes: O_RDONLY, O_WRONLY, or O_RDWR. These request opening the file read- only, write-only, or read/write, respectively. O_RDONLY is 0, O_WRONLY is 1, O_RDWR is 2, the flags use 2 bits for 3 states: 0 (0b00) / 1 (0b01) / 2 (0b10), the 2 bits will never be 3 (0b11). closes #288
Thanks for the report @CynicalBusiness and for the proposed fix @3cp. Let's come up with a valid test case first. The examples given in the description above ( |
Based on what I tested, although nodejs doc did not say, the readFile/sync/promise APIs support numeric option as if it's |
The argument flags must include one of the following access modes: O_RDONLY, O_WRONLY, or O_RDWR. These request opening the file read- only, write-only, or read/write, respectively. O_RDONLY is 0, O_WRONLY is 1, O_RDWR is 2, the flags use 2 bits for 3 states: 0 (0b00) / 1 (0b01) / 2 (0b10), the 2 bits will never be 3 (0b11). closes #288
Fix published in |
Had a bunch of tests failing with EBADF even after updating to
^4.10
(as mentioned in #245), finally managed to track it down.When trying to mock
fs.promises.readFile()
with thefs.constants.O_CREAT
flag, anEBADF
is raised if the file does not previously exist. If the file is created manually or the flag is not used, it reads normally or raisesENOENT
as it should.Reproducable:
node:
12.6.0
mock-fs:
4.10.4
The text was updated successfully, but these errors were encountered: