-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Check if path exists before returning from opendirSync #17846
base: main
Are you sure you want to change the base?
Conversation
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.
the problem with this approach is it will not set error.code.
@@ -1021,6 +1021,10 @@ function _toUnixTimestamp(time: any, name = "time") { | |||
function opendirSync(path, options) { | |||
// TODO: validatePath | |||
// validateString(path, "path"); | |||
if (!fs.existsSync(path)) { |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
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.
accessSync won't error if it's not a directory
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.
true. then instead, this PR should expose an opendir binding in src/bun.js/node/node_fs_binding.zig
to fs.ts
, and have a matching implementation function in src/bun.js/node/node_fs.zig
. this function would return a directory file descriptor. Then, there can be internal variants of readdir
that work on this file descriptor.
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.
Thanks for the pointers. I figured this would involve some Zig bindings, but wanted to ensure that there wasn't anything in JS-land that I was missing. I'm starting to work on the bindings now, should hopefully have something up this week, time permitting
describe("opendirSync", () => { | ||
it("should throw ENOENT on a nonexistent directory", () => { | ||
const dirName = Math.random().toString(8); | ||
expect(() => opendirSync(dirName)).toThrow("ENOENT"); |
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.
.toThrow({ code: "ENOENT" })
Closes #17581
What does this PR do?
How did you verify your code works?
One thing I don't quite see a pattern for yet is returning a system error (e.g.
ENOENT
) from JS code, but it seems like the typical way to do that is by putting the implementation into the Zig code.I figured I'd raise the PR while I look at how to do that in case there's a way to do it from JS though