Skip to content

Commit

Permalink
Merge pull request #175 from sapegin/fix-readfile-again
Browse files Browse the repository at this point in the history
Attempt to read a non-existing file should throw ENOENT
  • Loading branch information
streamich authored Jul 5, 2018
2 parents 3463019 + 322a730 commit 6abff36
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/__tests__/volume.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,12 +460,16 @@ describe('volume', () => {
// TODO: Check the right error message.
}
});
it('Attempt to read a directory should throw', () => {
it('Attempt to read a directory should throw EISDIR', () => {
const vol = new Volume;
vol.mkdirSync('/test');
const fn = () => vol.readFileSync('/test');
expect(fn).toThrowError('EISDIR');
});
it('Attempt to read a non-existing file should throw ENOENT', () => {
const fn = () => vol.readFileSync('/pizza.txt');
expect(fn).toThrowError('ENOENT');
});
});
describe('.readFile(path[, options], callback)', () => {
const vol = new Volume;
Expand Down
9 changes: 6 additions & 3 deletions src/volume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1017,9 +1017,12 @@ export class Volume {
} else {
const steps = filenameToSteps(id as string);
const link: Link = this.getResolvedLink(steps);
const node = link.getNode();
if(node.isDirectory())
throwError(EISDIR, 'open', link.getPath());

if(link) {
const node = link.getNode();
if(node.isDirectory())
throwError(EISDIR, 'open', link.getPath());
}

fd = this.openSync(id as TFilePath, flagsNum);
}
Expand Down

0 comments on commit 6abff36

Please sign in to comment.