Skip to content
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

compat(fs): opendir and opendirSync #2576

Merged
merged 15 commits into from
Sep 1, 2022
Merged

compat(fs): opendir and opendirSync #2576

merged 15 commits into from
Sep 1, 2022

Conversation

iuioiua
Copy link
Contributor

@iuioiua iuioiua commented Aug 29, 2022

For #802 and denoland/deno#18218. Note: my tests were previously passing fine on my machine but now they're not. I'm not sure what I changed.

Also, I'm not sure how to handle encoding and bufferSize options in regards to the current implementation of Dir.

@@ -34,6 +34,7 @@
"test-fs-append-file.js",
"test-fs-chmod-mask.js",
"test-fs-chmod.js",
"test-fs-opendir.js",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great to have this enabled! 👍

}
}

export const opendirPromise = promisify(opendir) as (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice to have the promise version 👍


try {
/** Throws if encoding is invalid */
new TextDecoder(options.encoding);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to be validateEncoding() call, which is defined in node/internal/validators.mjs. You can pass, for example, encoding: "binary" in opendir in node.js, but new TextDecoder("binary") throws.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, ok. Am I supposed to use path for the data parameter?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, sorry validateEncoding doesn't look correct for this according to the thrown error message. Probably assertEncoding (in node/internal/fs/utils.mjs) is the right choice here.

Copy link
Member

@kt3k kt3k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Nice work!

@iuioiua
Copy link
Contributor Author

iuioiua commented Aug 30, 2022

Please don’t merge yet. I need to check that callbacks can’t be called twice.

@iuioiua
Copy link
Contributor Author

iuioiua commented Aug 31, 2022

Please don’t merge yet. I need to check that callbacks can’t be called twice.

Ok, done, alongside some other improvements. My only remaining question is: is there any issue in using Deno.readDirSync(), a sync call, within the async version of opendir()?

@kt3k
Copy link
Member

kt3k commented Aug 31, 2022

My only remaining question is: is there any issue in using Deno.readDirSync(), a sync call, within the async version of opendir()?

Is that necessary for throwing error synchronously (to make it more compatible to node)? If so, that should be ok.

node/_fs/_fs_opendir_test.ts Outdated Show resolved Hide resolved
Copy link
Member

@kt3k kt3k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM again.

@iuioiua
Copy link
Contributor Author

iuioiua commented Aug 31, 2022

Last note (I think): test-fs-opendir.js is currently under ignore option for the Node test config file and it currently passes. When it's moved under the proper tests option, it fails due to limited current support of the Dirent class. The generated file has not been modified so this doesn't seem right.

@kt3k
Copy link
Member

kt3k commented Sep 1, 2022

test-fs-opendir.js is currently under ignore option for the Node test config file and it currently passes. When it's moved under the proper tests option, it fails due to limited current support of the Dirent class.

Ah, ok. I missed that point. There seem several things still missing for actually passing test-fs-opendir.js. I'd suggest we should revert the compatibility testing part (changes under node/_tools/). The current test cases in node/_fs/_fs_opendir_test.ts look enough for landing this

@iuioiua
Copy link
Contributor Author

iuioiua commented Sep 1, 2022

test-fs-opendir.js is currently under ignore option for the Node test config file and it currently passes. When it's moved under the proper tests option, it fails due to limited current support of the Dirent class.

Ah, ok. I missed that point. There seem several things still missing for actually passing test-fs-opendir.js. I'd suggest we should revert the compatibility testing part (changes under node/_tools/). The current test cases in node/_fs/_fs_opendir_test.ts look enough for landing this

Ok, done.

@kt3k
Copy link
Member

kt3k commented Sep 1, 2022

Thanks for updating!

@kt3k kt3k merged commit 6d2def2 into denoland:main Sep 1, 2022
@iuioiua iuioiua deleted the compat(fs)-opendir-and-opendirSync branch September 1, 2022 03:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants