From 43204b32c9fd29a1c9fe2deb54ab58d1cbb06680 Mon Sep 17 00:00:00 2001 From: Alberto Fernandez Date: Mon, 29 Aug 2016 11:31:35 +0100 Subject: [PATCH] [ls] Added try/catch block around lstatSync when options.long Temporary solution for https://github.com/shelljs/shelljs/issues/514 Adds the 'locked' attribute when file cannot be accessed. --- src/ls.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/ls.js b/src/ls.js index b1cd30eeb..1d1b41b4d 100644 --- a/src/ls.js +++ b/src/ls.js @@ -60,8 +60,15 @@ function _ls(options, paths) { relName = relName.replace(/\\/g, '/'); } if (options.long) { - stat = stat || fs.lstatSync(abs); - list.push(addLsAttributes(relName, stat)); + try { + stat = stat || fs.lstatSync(abs); + } catch(e) { + stat = { + locked: true + }; + } finally { + list.push(addLsAttributes(relName, stat)); + } } else { // list.push(path.relative(rel || '.', file)); list.push(relName);