From 7c31860954525d7eeb926e3f509b1b354346f340 Mon Sep 17 00:00:00 2001 From: Alexis THOMAS Date: Sun, 14 Feb 2021 23:00:51 +0100 Subject: [PATCH] Skip with warn for circular symlinks, instead of exit with error (#168) --- index.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 30df947..72aa30d 100644 --- a/index.js +++ b/index.js @@ -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'; @@ -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'; }