From 6aa6cf4105e9e9b32013673e3190d6deb639396e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Fri, 9 Nov 2018 09:40:23 -0800 Subject: [PATCH] fix(fs): make lstat optimistic --- lib/node/fs.js | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/node/fs.js b/lib/node/fs.js index 58e160a..eface77 100644 --- a/lib/node/fs.js +++ b/lib/node/fs.js @@ -112,19 +112,20 @@ function overrideNode () { }) patchFn('lstat', lstat => (p, cb) => { - const resolved = pkglock.resolve(p) - if (resolved == null) { - return lstat(p, cb) - } else if (!resolved) { - return notFoundError(p, cb) - } else { - pkglock.stat(resolved).then(stat => { - if (!stat) { - return notFoundError(p, cb) - } - cb(null, stat) - }, cb) - } + return lstat(p, (err, stat) => { + if (!err) { return cb(err, stat) } + const resolved = pkglock.resolve(p) + if (!resolved) { + return notFoundError(p, cb) + } else { + pkglock.stat(resolved).then(stat => { + if (!stat) { + notFoundError(p, cb) + } + cb(null, stat) + }, cb) + } + }) }) patchFn('statSync', statSync => p => {