Skip to content

Commit

Permalink
Merge pull request #495 from corwin-of-amber/o-dir
Browse files Browse the repository at this point in the history
fix: πŸ› handle opening directories with O_DIRECTORY
  • Loading branch information
streamich authored Jan 15, 2020
2 parents ccc8f90 + acdfac8 commit b686041
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/volume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const {
O_TRUNC,
O_APPEND,
O_SYNC,
O_DIRECTORY,
F_OK,
COPYFILE_EXCL,
COPYFILE_FICLONE_FORCE,
Expand Down Expand Up @@ -912,7 +913,13 @@ export class Volume {
if (!realLink) throw createError(ENOENT, 'open', link.getPath());

const node = realLink.getNode();
if (node.isDirectory() && flagsNum !== FLAGS.r) throw createError(EISDIR, 'open', link.getPath());

// Check whether node is a directory
if (node.isDirectory()) {
if ((flagsNum & (O_RDONLY | O_RDWR | O_WRONLY)) !== O_RDONLY) throw createError(EISDIR, 'open', link.getPath());
} else {
if (flagsNum & O_DIRECTORY) throw createError(ENOTDIR, 'open', link.getPath());
}

// Check node permissions
if (!(flagsNum & O_WRONLY)) {
Expand Down

0 comments on commit b686041

Please sign in to comment.