Skip to content

Commit

Permalink
Skip with warn for circular symlinks, instead of exit with error (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
ath0mas committed Feb 14, 2021
1 parent 887e9f3 commit 7c31860
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ const realpath = promisify(fs.realpath);
*/

const BANG = '!';
const NORMAL_FLOW_ERRORS = new Set(['ENOENT', 'EPERM', 'EACCES', 'ELOOP']);
const RECURSIVE_ERROR_CODE = 'READDIRP_RECURSIVE_ERROR';
const NORMAL_FLOW_ERRORS = new Set(['ENOENT', 'EPERM', 'EACCES', 'ELOOP', RECURSIVE_ERROR_CODE]);
const FILE_TYPE = 'files';
const DIR_TYPE = 'directories';
const FILE_DIR_TYPE = 'files_directories';
Expand Down Expand Up @@ -214,9 +215,11 @@ class ReaddirpStream extends Readable {
if (entryRealPathStats.isDirectory()) {
const len = entryRealPath.length;
if (full.startsWith(entryRealPath) && full.substr(len, 1) === sysPath.sep) {
return this._onError(new Error(
const recursiveError = new Error(
`Circular symlink detected: "${full}" points to "${entryRealPath}"`
));
);
recursiveError.code = RECURSIVE_ERROR_CODE;
return this._onError(recursiveError);
}
return 'directory';
}
Expand Down

0 comments on commit 7c31860

Please sign in to comment.