Skip to content

Commit

Permalink
Merge pull request #72 from JSMonk/master
Browse files Browse the repository at this point in the history
fix(Windows): add variant when windows throw EPERM instead ENOENT.
  • Loading branch information
paulmillr authored Apr 16, 2019
2 parents 823c307 + 0e16b6c commit 644aade
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const supportsDirent = 'Dirent' in fs;

const BANG = '!';
const ENOENT = 'ENOENT';
const EPERM = 'EPERM';
const FILE_TYPE = 'files';
const DIR_TYPE = 'directories';
const FILE_DIR_TYPE = 'files_directories';
Expand All @@ -27,6 +28,8 @@ const TYPES = [FILE_TYPE, DIR_TYPE, FILE_DIR_TYPE, ALL_TYPE];
const FILE_TYPES = Object.freeze(new Set([FILE_TYPE, FILE_DIR_TYPE, ALL_TYPE]));
const DIR_TYPES = Object.freeze(new Set([DIR_TYPE, FILE_DIR_TYPE, ALL_TYPE]));

const isNormalFlowError = err => err.code === ENOENT || (process.platform === 'win32' && err.code === EPERM);

const normalizeFilter = (filter) => {
if (filter === undefined) return;
if (typeof filter === 'function') return filter;
Expand Down Expand Up @@ -122,7 +125,7 @@ class ReaddirpStream extends Readable {
try {
files = await readdir(parentPath, this._readdir_options);
} catch (error) {
if (error.code !== ENOENT) throw error;
if (!isNormalFlowError(error)) throw error;
}
this.filesToRead--;

Expand All @@ -144,7 +147,7 @@ class ReaddirpStream extends Readable {
try {
stats = await this._stat(fullPath);
} catch (error) {
if (error.code === ENOENT) {
if (isNormalFlowError(error)) {
this.filesToRead--;
continue;
} else {
Expand Down

0 comments on commit 644aade

Please sign in to comment.