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

Deno.open createNew not working #71

Closed
tiloio opened this issue Dec 28, 2021 · 2 comments · Fixed by #73
Closed

Deno.open createNew not working #71

tiloio opened this issue Dec 28, 2021 · 2 comments · Fixed by #73

Comments

@tiloio
Copy link
Contributor

tiloio commented Dec 28, 2021

When I run await Deno.open('./test-file', { createNew: true, write: true }); I will get the following error when I use the deno shims with the https://github.com/denoland/dnt build esm output.

node_modules/@deno/shim-deno/dist/deno/internal/fs_flags.js:81
    throw new errors.BadResource("EINVAL: Invalid fs flags.");
          ^

BadResource [Error]: EINVAL: Invalid fs flags.

I created an example to show the error: https://github.com/tiloio/deno-open-create-new-shim-bug

There is no way to have not an error if I set createNew to true:
https://github.com/denoland/node_deno_shims/blob/430ad2bfade33c532a9a078fc4e79a48831ce5fe/packages/shim-deno/src/deno/internal/fs_flags.ts#L35

@tiloio
Copy link
Contributor Author

tiloio commented Dec 28, 2021

According to the node and deno docs I would say the negation here is wrong:
https://github.com/denoland/node_deno_shims/blob/430ad2bfade33c532a9a078fc4e79a48831ce5fe/packages/shim-deno/src/deno/internal/fs_flags.ts#L67

Node docs

Constant Description
O_EXCL Flag indicating that opening a file should fail if the O_CREAT flag is set and the file already exists.
O_NOCTTY Flag indicating that if path identifies a terminal device, opening the path shall not cause that terminal to become the controlling terminal for the process (if the process does not already have one).

Deno docs:

   /** Defaults to `false`. If set to `true`, no file, directory, or symlink is
     * allowed to exist at the target location. Requires write or append
     * access to be used. When createNew is set to `true`, create and truncate
     * are ignored. */
    createNew?: boolean;

tiloio added a commit to tiloio/node_deno_shims that referenced this issue Dec 28, 2021
@tiloio
Copy link
Contributor Author

tiloio commented Dec 28, 2021

Created PR #72 to address this issue.

dsherret pushed a commit to dsherret/node_shims that referenced this issue Jan 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant