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

Handling fs.constants.O_DIRECTORY flag #494

Closed
corwin-of-amber opened this issue Jan 15, 2020 · 4 comments · Fixed by #495, plastikfan/jaxom-ts#60 or plastikfan/zenobia-ts#38
Closed

Handling fs.constants.O_DIRECTORY flag #494

corwin-of-amber opened this issue Jan 15, 2020 · 4 comments · Fixed by #495, plastikfan/jaxom-ts#60 or plastikfan/zenobia-ts#38
Labels

Comments

@corwin-of-amber
Copy link
Contributor

corwin-of-amber commented Jan 15, 2020

In Node.js, it is possible to open a directory with fs.open or fs.openSync, specifying read access and optionally the flag fs.constants.O_DIRECTORY.
The effect of the flag is only that Node.js will raise ENOTDIR if the file is not a directory.

> fd = fs.openSync("/tmp/a", fs.constants.O_RDONLY)
29
> fd = fs.openSync("/tmp/a", fs.constants.O_RDONLY | fs.constants.O_DIRECTORY)
Thrown:
Error: ENOTDIR: not a directory, open '/tmp/a'
    at Object.openSync (fs.js:440:3) {
  errno: -20,
  syscall: 'open',
  code: 'ENOTDIR',
  path: '/tmp/a'
}
> fs.openSync('/', fs.constants.O_RDONLY)
30
> fs.openSync('/', fs.constants.O_RDONLY | fs.constants.O_DIRECTORY)
31

In memfs, the flag is ignored when opening a file and rejected when attempting to open a directory (openLink thinks the requested access is not read-only).

> m.openSync('/', fs.constants.O_RDONLY)
openLink true 0 0
2147483646
> m.openSync('/', fs.constants.O_RDONLY | fs.constants.O_DIRECTORY)
Thrown:
Error: EISDIR: illegal operation on a directory, open
    at createError (node_modules/memfs/lib/volume.js:131:17)
    at Volume.openLink (node_modules/memfs/lib/volume.js:774:19)
    at Volume.openFile (node_modules/memfs/lib/volume.js:806:25)
    at Volume.openBase (node_modules/memfs/lib/volume.js:811:25)
    at Volume.openSync (/Users/corwin/var/workspace/Web.OS.Shell/node_modules/memfs/lib/volume.js:822:21) {
  code: 'EISDIR'
}
@corwin-of-amber
Copy link
Contributor Author

The issue has been patched in this fork, although not completely. I will try to make a PR based on that.

@streamich
Copy link
Owner

@corwin-of-amber thanks!

@corwin-of-amber
Copy link
Contributor Author

Extremely welcome 😄

streamich pushed a commit that referenced this issue Jan 15, 2020
## [3.0.4](v3.0.3...v3.0.4) (2020-01-15)

### Bug Fixes

* 🐛 handle opening directories with O_DIRECTORY ([acdfac8](acdfac8)), closes [#494](#494)
@streamich
Copy link
Owner

🎉 This issue has been resolved in version 3.0.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

corwin-of-amber added a commit to corwin-of-amber/wasi-kernel that referenced this issue Jan 15, 2020
Now contains O_DIRECTORY fix.
(streamich/memfs#494)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants