From aed9a61c9f88f38f741f8275f743eb2c38298edb Mon Sep 17 00:00:00 2001 From: Aaron Turner Date: Tue, 15 Oct 2019 16:29:21 -0700 Subject: [PATCH] Implemented Syrus' Volume fix --- src/__tests__/volume.test.ts | 8 ++++++++ src/volume.ts | 8 +++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/__tests__/volume.test.ts b/src/__tests__/volume.test.ts index 4f5f473c..6c7d21f9 100644 --- a/src/__tests__/volume.test.ts +++ b/src/__tests__/volume.test.ts @@ -3,6 +3,7 @@ import { Link, Node } from '../node'; import Stats from '../Stats'; import Dirent from '../Dirent'; import { Volume, filenameToSteps, StatWatcher } from '../volume'; +import { constants } from '../constants'; import hasBigInt from './hasBigInt'; describe('volume', () => { @@ -282,6 +283,13 @@ describe('volume', () => { expect(typeof fd).toBe('number'); expect(fd).toBeGreaterThan(0); }); + it('Create new directory at root (/)', () => { + vol.mkdirSync('/abc'); + const fd = vol.openSync('/abc', constants.O_DIRECTORY); + // expect(vol.root.getChild('test.txt')).toBeInstanceOf(Link); + expect(typeof fd).toBe('number'); + expect(fd).toBeGreaterThan(0); + }); it('Error on file not found', () => { try { vol.openSync('/non-existing-file.txt', 'r'); diff --git a/src/volume.ts b/src/volume.ts index 7b356902..91c5ed34 100644 --- a/src/volume.ts +++ b/src/volume.ts @@ -904,7 +904,13 @@ export class Volume { if (!realLink) throwError(ENOENT, 'open', link.getPath()); const node = realLink.getNode(); - if (node.isDirectory() && flagsNum !== FLAGS.r) throwError(EISDIR, 'open', link.getPath()); + if (node.isDirectory()) { + const isRead = flagsNum === FLAGS.r; + const isDir = (flagsNum & constants.O_DIRECTORY) !== 0; + if (!isRead && !isDir) { + throwError(EISDIR, 'open', link.getPath()); + } + } // Check node permissions if (!(flagsNum & O_WRONLY)) {