From f89eede9530c3f5bd8d8a523be1927d396cda662 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Thu, 12 Mar 2020 19:13:39 +0800 Subject: [PATCH] fix: should throw `EEXIST` instead of `EISDIR` on `mkdirSync('/')` The `EISDIR` implementation is considered a bug in BSD operating systems. See the bug report at https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=59739 and the POSIX specification at https://pubs.opengroup.org/onlinepubs/9699919799/functions/mkdir.html --- src/__tests__/volume/__snapshots__/mkdirSync.test.ts.snap | 2 +- src/volume.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/__tests__/volume/__snapshots__/mkdirSync.test.ts.snap b/src/__tests__/volume/__snapshots__/mkdirSync.test.ts.snap index 976964a4..d91328f6 100644 --- a/src/__tests__/volume/__snapshots__/mkdirSync.test.ts.snap +++ b/src/__tests__/volume/__snapshots__/mkdirSync.test.ts.snap @@ -1,5 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`mkdirSync throws when creating root directory 1`] = `"EISDIR: illegal operation on a directory, mkdir '/'"`; +exports[`mkdirSync throws when creating root directory 1`] = `"EEXIST: file already exists, mkdir '/'"`; exports[`mkdirSync throws when re-creating existing directory 1`] = `"EEXIST: file already exists, mkdir '/new-dir'"`; diff --git a/src/volume.ts b/src/volume.ts index 73552fd7..8849d71c 100644 --- a/src/volume.ts +++ b/src/volume.ts @@ -1812,7 +1812,7 @@ export class Volume { // This will throw if user tries to create root dir `fs.mkdirSync('/')`. if (!steps.length) { - throw createError(EISDIR, 'mkdir', filename); + throw createError(EEXIST, 'mkdir', filename); } const dir = this.getLinkParentAsDirOrThrow(filename, 'mkdir');