Skip to content

Commit

Permalink
Merge pull request #169 from ath0mas/fix/168-recusive-warn
Browse files Browse the repository at this point in the history
Skip with warn for circular symlinks
  • Loading branch information
paulmillr committed Feb 18, 2021
2 parents 887e9f3 + 7c31860 commit 62eea1a
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 62eea1a

Please sign in to comment.